Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w3c(phase 3): ensure last datadog parent id is always recorded #3631

Merged
merged 12 commits into from
Jun 7, 2024
8 changes: 7 additions & 1 deletion lib/datadog/tracing/distributed/propagation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ def extract(data)
if (tracecontext_digest = propagator.extract(data))
# Only parse if it represent the same trace as the successfully extracted one
next unless tracecontext_digest.trace_id == extracted_trace_digest.trace_id

tracecontext_digest.trace_distributed_tags |= {}
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
extracted_trace_digest.trace_distributed_tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = if tracecontext_digest.span_id == extracted_trace_digest.span_id
"%.16x" % tracecontext_digest.span_id
else
# Preserve the last datadog parent id in `trace_distributed_tags`
tracecontext_digest.trace_distributed_tags.fetch(Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID, Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT)
end
# Preserve the `tracestate`
extracted_trace_digest = extracted_trace_digest.merge(
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
trace_state: tracecontext_digest.trace_state,
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/distributed/trace_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def extract(data)
end

tags ||= {}
tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = ts_parent_id || '0000000000000000'
tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = ts_parent_id || Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT

TraceDigest.new(
span_id: parent_id,
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/metadata/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module Distributed
TAG_SAMPLING_PRIORITY = '_sampling_priority_v1'

TAG_DD_PARENT_ID = '_dd.parent_id'
DD_PARENT_ID_DEFAULT = '0000000000000000'

# Trace tags with this prefix will propagate from a trace through distributed tracing.
# Distributed headers tags with this prefix will be injected into the active trace.
Expand Down
Loading