Sha256: 1b25b79ff0755f6315f90fda22eec901ff7560c0ad7f65a2b6ef93527be50e4e

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# typed: true
# frozen_string_literal: true

require 'ddtrace/ext/http'

module Datadog
  module Profiling
    module TraceIdentifiers
      # Used by Datadog::Profiling::TraceIdentifiers::Helper to get the trace identifiers (root span id and span id)
      # for a given thread, if there is an active trace for that thread in the supplied tracer object.
      class Ddtrace
        def initialize(tracer:)
          @tracer = (tracer if tracer.respond_to?(:call_context))
        end

        def trace_identifiers_for(thread)
          return unless @tracer

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

          span, root_span = context.current_span_and_root_span
          return unless span && root_span

          root_span_id = root_span.span_id || 0
          span_id = span.span_id || 0

          [root_span_id, span_id, maybe_extract_resource(root_span)] if root_span_id != 0 && span_id != 0
        end

        private

        # 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 :)
        def maybe_extract_resource(root_span)
          root_span.resource if root_span.span_type == Datadog::Ext::HTTP::TYPE_INBOUND
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/profiling/trace_identifiers/ddtrace.rb
ddtrace-0.54.1 lib/ddtrace/profiling/trace_identifiers/ddtrace.rb
ddtrace-0.54.0 lib/ddtrace/profiling/trace_identifiers/ddtrace.rb