Class: Datadog::Contrib::ActiveSupport::Notifications::Subscription
- Inherits:
-
Object
- Object
- Datadog::Contrib::ActiveSupport::Notifications::Subscription
- Defined in:
- lib/ddtrace/contrib/active_support/notifications/subscription.rb
Overview
An ActiveSupport::Notification subscription that wraps events with tracing.
Defined Under Namespace
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#span_name ⇒ Object
Returns the value of attribute span_name.
-
#tracer ⇒ Object
Returns the value of attribute tracer.
Instance Method Summary collapse
- #after_trace(&block) ⇒ Object
- #before_trace(&block) ⇒ Object
-
#call(name, start, finish, id, payload) ⇒ Object
ActiveSupport 3.x calls this.
-
#finish(name, id, payload) ⇒ Object
ActiveSupport 4+ calls this on finish.
-
#initialize(tracer, span_name, options, &block) ⇒ Subscription
constructor
A new instance of Subscription.
-
#start(name, id, payload) ⇒ Object
ActiveSupport 4+ calls this on start.
- #subscribe(pattern) ⇒ Object
- #unsubscribe(pattern) ⇒ Object
- #unsubscribe_all ⇒ Object
Constructor Details
#initialize(tracer, span_name, options, &block) ⇒ Subscription
Returns a new instance of Subscription.
12 13 14 15 16 17 18 19 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 12 def initialize(tracer, span_name, , &block) raise ArgumentError, 'Must be given a block!' unless block_given? @tracer = tracer @span_name = span_name @options = @handler = Handler.new(&block) @callbacks = Callbacks.new end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 7 def @options end |
#span_name ⇒ Object
Returns the value of attribute span_name.
7 8 9 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 7 def span_name @span_name end |
#tracer ⇒ Object
Returns the value of attribute tracer.
7 8 9 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 7 def tracer @tracer end |
Instance Method Details
#after_trace(&block) ⇒ Object
41 42 43 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 41 def after_trace(&block) callbacks.add(:after_trace, &block) if block_given? end |
#before_trace(&block) ⇒ Object
37 38 39 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 37 def before_trace(&block) callbacks.add(:before_trace, &block) if block_given? end |
#call(name, start, finish, id, payload) ⇒ Object
ActiveSupport 3.x calls this
22 23 24 25 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 22 def call(name, start, finish, id, payload) start_span(name, id, payload, start) finish_span(name, id, payload, finish) end |
#finish(name, id, payload) ⇒ Object
ActiveSupport 4+ calls this on finish
33 34 35 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 33 def finish(name, id, payload) finish_span(name, id, payload) end |
#start(name, id, payload) ⇒ Object
ActiveSupport 4+ calls this on start
28 29 30 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 28 def start(name, id, payload) start_span(name, id, payload) end |
#subscribe(pattern) ⇒ Object
45 46 47 48 49 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 45 def subscribe(pattern) return false if subscribers.key?(pattern) subscribers[pattern] = ::ActiveSupport::Notifications.subscribe(pattern, self) true end |
#unsubscribe(pattern) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 51 def unsubscribe(pattern) return false unless subscribers.key?(pattern) ::ActiveSupport::Notifications.unsubscribe(subscribers[pattern]) subscribers.delete(pattern) true end |
#unsubscribe_all ⇒ Object
58 59 60 61 62 |
# File 'lib/ddtrace/contrib/active_support/notifications/subscription.rb', line 58 def unsubscribe_all return false if subscribers.empty? subscribers.keys.each { |pattern| unsubscribe(pattern) } true end |