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

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/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.



131
132
133
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 131

def initialize
  @blocks = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



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

def blocks
  @blocks
end

Instance Method Details

#add(key, &block) ⇒ Object



135
136
137
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 135

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

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



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 139

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