Module: Datadog::Contrib::ActiveSupport::Notifications::Event::ClassMethods

Defined in:
lib/ddtrace/contrib/active_support/notifications/event.rb

Overview

Redefines some class behaviors for a Subscriber to make it a bit simpler for an Event.

Constant Summary collapse

DEFAULT_TRACER =
-> { Datadog.tracer }

Instance Method Summary collapse

Instance Method Details

#payload_exception(payload) ⇒ Object



67
68
69
70
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 67

def payload_exception(payload)
  payload[:exception_object] ||
    payload[:exception] # Fallback for ActiveSupport < 5.0
end

#report_if_exception(span, payload) ⇒ Object



62
63
64
65
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 62

def report_if_exception(span, payload)
  exception = payload_exception(payload)
  span.set_error(payload[:exception]) if exception
end

#span_optionsObject



54
55
56
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 54

def span_options
  {}
end

#subscribe(pattern = nil, span_name = nil, options = nil, tracer = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 38

def subscribe(pattern = nil, span_name = nil, options = nil, tracer = nil)
  if supported?
    super(
      pattern || event_name,
      span_name || self.span_name,
      options || span_options,
      tracer || self.tracer,
      &method(:process)
    )
  end
end

#subscribe!Object

Publicly exposes protected method subscribe!



25
26
27
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 25

def subscribe! # rubocop:disable Lint/UselessMethodDefinition
  super
end

#subscription(span_name = nil, options = nil, tracer = nil) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 29

def subscription(span_name = nil, options = nil, tracer = nil)
  super(
    span_name || self.span_name,
    options || span_options,
    tracer || self.tracer,
    &method(:process)
  )
end

#supported?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 50

def supported?
  true
end

#tracerObject



58
59
60
# File 'lib/ddtrace/contrib/active_support/notifications/event.rb', line 58

def tracer
  DEFAULT_TRACER
end