Class: Datadog::Profiling::TraceIdentifiers::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/profiling/trace_identifiers/helper.rb

Overview

Helper used to retrieve the trace identifiers (root span id and span id) for a given thread, if there is an active trace for that thread for the supported tracing APIs.

This data is used to connect profiles to the traces -- samples in a profile will be tagged with this data and the profile can be filtered down to look at only the samples for a given trace.

Instance Method Summary collapse

Constructor Details

#initialize(tracer:, endpoint_collection_enabled:, supported_apis: DEFAULT_SUPPORTED_APIS.map { |api| api.new(tracer: tracer) }) ⇒ Helper

Returns a new instance of Helper.



20
21
22
23
24
25
26
27
28
# File 'lib/ddtrace/profiling/trace_identifiers/helper.rb', line 20

def initialize(
  tracer:,
  # If this is disabled, the helper will strip the optional trace_resource_container even if provided by the api
  endpoint_collection_enabled:,
  supported_apis: DEFAULT_SUPPORTED_APIS.map { |api| api.new(tracer: tracer) }
)
  @endpoint_collection_enabled = endpoint_collection_enabled
  @supported_apis = supported_apis
end

Instance Method Details

#trace_identifiers_for(thread) ⇒ Object

Expected output of the #trace_identifiers_for duck type is [root_span_id, span_id, (optional trace_resource_container)]



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ddtrace/profiling/trace_identifiers/helper.rb', line 32

def trace_identifiers_for(thread)
  @supported_apis.each do |api|
    trace_identifiers = api.trace_identifiers_for(thread)

    if trace_identifiers
      return @endpoint_collection_enabled ? trace_identifiers : trace_identifiers[0..1]
    end
  end

  nil
end