class Datadog::Profiling::TraceIdentifiers::Ddtrace

Used by Datadog::Profiling::TraceIdentifiers::Helper to get the trace identifiers (trace id and span id) for a given thread, if there is an active trace for that thread in Datadog.tracer.

Public Class Methods

new(tracer: nil) click to toggle source
# File lib/ddtrace/profiling/trace_identifiers/ddtrace.rb, line 12
def initialize(tracer: nil)
  @tracer = (tracer if tracer.respond_to?(:call_context))
end

Public Instance Methods

trace_identifiers_for(thread) click to toggle source
# File lib/ddtrace/profiling/trace_identifiers/ddtrace.rb, line 16
def trace_identifiers_for(thread)
  return unless @tracer

  context = @tracer.call_context(thread)
  return unless context

  trace_id = context.trace_id || 0
  span_id = context.span_id || 0

  [trace_id, span_id, maybe_extract_resource(context.current_root_span)] if trace_id != 0 && span_id != 0
end

Private Instance Methods

maybe_extract_resource(root_span) click to toggle source

NOTE: Currently we're only interested in HTTP service endpoints. Over time, this list may be expanded. Resources MUST NOT include personal identifiable information (PII); this should not be the case with ddtrace integrations, but worth mentioning just in case :)

# File lib/ddtrace/profiling/trace_identifiers/ddtrace.rb, line 33
def maybe_extract_resource(root_span)
  return unless root_span

  root_span.resource_container if root_span.span_type == Datadog::Ext::HTTP::TYPE_INBOUND
end