class Pantomath::Instrumentation::AbstractTracer

Attributes

context[R]

Public Class Methods

exclude_pattern() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 12
def exclude_pattern
  Pantomath.configuration.exclude_patterns.send(config_name)
end
new(context) click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 29
def initialize(context)
  @context = context
end
tag_collector() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 8
def tag_collector
  Pantomath.configuration.tag_collectors.send(config_name)
end

Private Class Methods

config_name() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 17
def config_name
  @config_name ||= group_name.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
end
group_name() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 21
def group_name
  name.split("::")[2]
end

Public Instance Methods

trace() { || ... } click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 33
def trace(&block)
  return yield if exclude?

  track(&block)
end

Private Instance Methods

close_span() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 81
def close_span
  Pantomath.active_scope.close if Pantomath.active_scope
end
collected_tags() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 89
def collected_tags
  return {} unless tag_collector

  tag_collector.is_a?(Proc) ? context.instance_exec(&tag_collector) : context.send(tag_collector)
end
exclude?() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 51
def exclude?
  exclude_pattern && span_name =~ exclude_pattern
end
exclude_pattern() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 95
def exclude_pattern
  self.class.exclude_pattern
end
handle_exception(exception) click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 103
def handle_exception(exception)
  Pantomath.active_span.set_tag(:error, true)
  Pantomath.active_span.log_kv(
    "event": "error",
    "error.object": exception,
    stack: exception.backtrace.take(10) # This is important because stacktrace can be too long which exceeds the maximum udp messages size
  )
  raise exception
end
set_status() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 63
def set_status
  Pantomath.active_span.set_tag(*status) if status
end
span_name() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 67
def span_name
  raise "Should be implemented"
end
span_tags() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 85
def span_tags
  tags.merge!(collected_tags)
end
start_span() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 55
def start_span
  Pantomath.tracer.start_active_span(
    span_name,
    child_of: tracer_context,
    tags: span_tags
  )
end
status() click to toggle source

Return an array of status tag key and status to set status of Span.

# File lib/pantomath/instrumentation/abstract_tracer.rb, line 79
def status; end
tag_collector() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 99
def tag_collector
  self.class.tag_collector
end
tags() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 71
def tags
  raise "Should be implemented"
end
tracer_context() click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 75
def tracer_context; end
track() { || ... } click to toggle source
# File lib/pantomath/instrumentation/abstract_tracer.rb, line 40
def track
  start_span
  result = yield
  set_status
  result
rescue Exception => e
  handle_exception(e)
ensure
  close_span
end