Class: Datadog::Contrib::ActiveSupport::Notifications::Subscription::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/contrib/active_support/notifications/subscription.rb

Overview

Wrapper for subscription callbacks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



126
127
128
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 126

def initialize
  @blocks = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



124
125
126
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 124

def blocks
  @blocks
end

Instance Method Details

#add(key, &block) ⇒ Object



130
131
132
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 130

def add(key, &block)
  blocks_for(key) << block if block_given?
end

#run(event, key, *args) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 134

def run(event, key, *args)
  blocks_for(key).each do |callback|
    begin
      callback.call(event, key, *args)
    rescue StandardError => e
      Datadog::Tracer.log.debug(
        "ActiveSupport::Notifications '#{key}' callback for '#{event}' failed: #{e.message}"
      )
    end
  end
end