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.



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

def initialize
  @blocks = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



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

def blocks
  @blocks
end

Instance Method Details

#add(key, &block) ⇒ Object



141
142
143
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 141

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

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



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 145

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