Class: Labkit::Tracing::AbstractInstrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/labkit/tracing/abstract_instrumenter.rb

Overview

Instance Method Summary collapse

Instance Method Details

#finish(_name, _id, payload) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/labkit/tracing/abstract_instrumenter.rb', line 15

def finish(_name, _id, payload)
  span_wrapper = scope_stack.pop

  Labkit::Tracing::TracingUtils.log_common_fields_on_span(span_wrapper, span_name(payload))

  # exception_object is the standard exception payload from ActiveSupport::Notifications
  # https://github.com/rails/rails/blob/v6.0.3.1/activesupport/lib/active_support/notifications/instrumenter.rb#L26
  exception = payload[:exception_object].presence || payload[:exception].presence
  span_wrapper.set_error(exception)

  tags(payload).each do |k, v|
    span_wrapper.set_tag(k, v)
  end

  span_wrapper.close
end

#scope_stackObject



32
33
34
# File 'lib/labkit/tracing/abstract_instrumenter.rb', line 32

def scope_stack
  Thread.current[:_labkit_trace_scope_stack] ||= []
end

#span_name(_payload) ⇒ Object



36
37
38
# File 'lib/labkit/tracing/abstract_instrumenter.rb', line 36

def span_name(_payload)
  raise "span_name not implemented"
end

#start(_name, _id, payload) ⇒ Object



9
10
11
12
13
# File 'lib/labkit/tracing/abstract_instrumenter.rb', line 9

def start(_name, _id, payload)
  span_wrapper = Labkit::Tracing::TracingUtils.tracer.start_active_span(span_name(payload))

  scope_stack.push span_wrapper
end

#tags(_payload) ⇒ Object



40
41
42
# File 'lib/labkit/tracing/abstract_instrumenter.rb', line 40

def tags(_payload)
  {}
end