Class: Datadog::Tracing::Contrib::ActiveSupport::Notifications::Subscription
- Inherits:
-
Object
- Object
- Datadog::Tracing::Contrib::ActiveSupport::Notifications::Subscription
- Defined in:
- lib/datadog/tracing/contrib/active_support/notifications/subscription.rb
Overview
An ActiveSupport::Notification subscription that wraps events with tracing.
Defined Under Namespace
Instance Attribute Summary collapse
-
#span_name ⇒ Object
Returns the value of attribute span_name.
-
#span_options ⇒ Object
Returns the value of attribute span_options.
Instance Method Summary collapse
- #after_trace(&block) ⇒ Object
- #before_trace(&block) ⇒ Object
-
#finish(name, id, payload) ⇒ Object
Called by ActiveSupport on event finish.
-
#initialize(span_name, span_options, on_start: nil, on_finish: nil, trace: nil) ⇒ Subscription
constructor
A new instance of Subscription.
-
#start(name, id, payload) ⇒ Object
Called by ActiveSupport on event start.
- #subscribe(pattern) ⇒ Object
- #unsubscribe(pattern) ⇒ Object
- #unsubscribe_all ⇒ Object
Constructor Details
#initialize(span_name, span_options, on_start: nil, on_finish: nil, trace: nil) ⇒ Subscription
Returns a new instance of Subscription.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 21 def initialize(span_name, , on_start: nil, on_finish: nil, trace: nil) raise ArgumentError, 'Must be given either on_start or on_finish' unless on_start || on_finish @span_name = span_name @span_options = @on_start = Handler.new(on_start) @on_finish = Handler.new(on_finish) @trace = trace @callbacks = Callbacks.new end |
Instance Attribute Details
#span_name ⇒ Object
Returns the value of attribute span_name.
10 11 12 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 10 def span_name @span_name end |
#span_options ⇒ Object
Returns the value of attribute span_options.
10 11 12 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 10 def @span_options end |
Instance Method Details
#after_trace(&block) ⇒ Object
46 47 48 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 46 def after_trace(&block) callbacks.add(:after_trace, &block) if block end |
#before_trace(&block) ⇒ Object
42 43 44 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 42 def before_trace(&block) callbacks.add(:before_trace, &block) if block end |
#finish(name, id, payload) ⇒ Object
Called by ActiveSupport on event finish
38 39 40 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 38 def finish(name, id, payload) finish_span(name, id, payload) if payload[:datadog_span] end |
#start(name, id, payload) ⇒ Object
Called by ActiveSupport on event start
33 34 35 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 33 def start(name, id, payload) start_span(name, id, payload) if @trace&.call(name, payload) end |
#subscribe(pattern) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 50 def subscribe(pattern) return false if subscribers.key?(pattern) subscribers[pattern] = ::ActiveSupport::Notifications.subscribe(pattern, self) true end |
#unsubscribe(pattern) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 57 def unsubscribe(pattern) return false unless subscribers.key?(pattern) ::ActiveSupport::Notifications.unsubscribe(subscribers[pattern]) subscribers.delete(pattern) true end |
#unsubscribe_all ⇒ Object
65 66 67 68 69 70 |
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 65 def unsubscribe_all return false if subscribers.empty? subscribers.each_key { |pattern| unsubscribe(pattern) } true end |