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

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/contrib/active_support/notifications/subscription.rb

Overview

An ActiveSupport::Notification subscription that wraps events with tracing.

Defined Under Namespace

Classes: Callbacks, Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(span_name, options, &block) ⇒ Subscription

Returns a new instance of Subscription.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 12

def initialize(span_name, options, &block)
  raise ArgumentError, 'Must be given a block!' unless block

  @span_name = span_name
  @options = options
  @handler = Handler.new(&block)
  @callbacks = Callbacks.new
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 8

def options
  @options
end

#span_nameObject

Returns the value of attribute span_name.



8
9
10
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 8

def span_name
  @span_name
end

Instance Method Details

#after_trace(&block) ⇒ Object



41
42
43
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 41

def after_trace(&block)
  callbacks.add(:after_trace, &block) if block
end

#before_trace(&block) ⇒ Object



37
38
39
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 37

def before_trace(&block)
  callbacks.add(:before_trace, &block) if block
end

#call(name, start, finish, id, payload) ⇒ Object

ActiveSupport 3.x calls this



22
23
24
25
# File 'lib/datadog/tracing/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/datadog/tracing/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/datadog/tracing/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
50
# File 'lib/datadog/tracing/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



52
53
54
55
56
57
58
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 52

def unsubscribe(pattern)
  return false unless subscribers.key?(pattern)

  ::ActiveSupport::Notifications.unsubscribe(subscribers[pattern])
  subscribers.delete(pattern)
  true
end

#unsubscribe_allObject



60
61
62
63
64
65
# File 'lib/datadog/tracing/contrib/active_support/notifications/subscription.rb', line 60

def unsubscribe_all
  return false if subscribers.empty?

  subscribers.each_key { |pattern| unsubscribe(pattern) }
  true
end