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.



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

def initialize
  @blocks = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



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

def blocks
  @blocks
end

Instance Method Details

#add(key, &block) ⇒ Object



133
134
135
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 133

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

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



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 137

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