Class: Datadog::Tracing::Distributed::TraceContext
- Inherits:
-
Object
- Object
- Datadog::Tracing::Distributed::TraceContext
- Defined in:
- lib/datadog/tracing/distributed/trace_context.rb
Overview
W3C Trace Context propagator implementation, version 00.
The trace is propagated through two fields: traceparent and tracestate.
Constant Summary collapse
- TRACEPARENT_KEY =
"traceparent"- TRACESTATE_KEY =
"tracestate"- SPEC_VERSION =
"00"
Instance Method Summary collapse
- #extract(data) ⇒ Object
-
#initialize(fetcher:, traceparent_key: TRACEPARENT_KEY, tracestate_key: TRACESTATE_KEY) ⇒ TraceContext
constructor
A new instance of TraceContext.
- #inject!(digest, data) ⇒ Object
Constructor Details
#initialize(fetcher:, traceparent_key: TRACEPARENT_KEY, tracestate_key: TRACESTATE_KEY) ⇒ TraceContext
Returns a new instance of TraceContext.
17 18 19 20 21 22 23 24 25 |
# File 'lib/datadog/tracing/distributed/trace_context.rb', line 17 def initialize( fetcher:, traceparent_key: TRACEPARENT_KEY, tracestate_key: TRACESTATE_KEY ) @fetcher = fetcher @traceparent_key = traceparent_key @tracestate_key = tracestate_key end |
Instance Method Details
#extract(data) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/datadog/tracing/distributed/trace_context.rb', line 41 def extract(data) fetcher = @fetcher.new(data) trace_id, parent_id, sampled, trace_flags = extract_traceparent(fetcher[@traceparent_key]) return unless trace_id # Could not parse traceparent trace_state = TraceState.extract(fetcher[@tracestate_key]) dd = trace_state.datadog ot = trace_state.open_telemetry = dd. sampling_priority = parse_priority_sampling(sampled, dd.sampling_priority) do |decision| case decision when String ||= {} [Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER] = decision when :drop &.delete(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER) end end ||= {} [Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = dd.ts_parent_id || Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT TraceDigest.new( span_id: parent_id, trace_id: trace_id, trace_origin: dd.origin, trace_sampling_priority: sampling_priority, trace_distributed_tags: , trace_flags: trace_flags, trace_state: trace_state.unknown_vendors, trace_state_unknown_fields: dd.unknown_fields, trace_otel_random_value: ot.random_value, trace_otel_threshold: ot.threshold, trace_otel_unknown_fields: ot.unknown_fields, span_remote: true, ) end |
#inject!(digest, data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datadog/tracing/distributed/trace_context.rb', line 27 def inject!(digest, data) return if digest.nil? if (traceparent = build_traceparent(digest)) data[@traceparent_key] = traceparent if (tracestate = TraceState.serialize_digest(digest)) data[@tracestate_key] = tracestate end end data end |