Skip to content

Commit

Permalink
propagate lpid if spans are not equal
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed May 9, 2024
1 parent 93c11c8 commit 0e3a0f1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/datadog/tracing/distributed/propagation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ def 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 |= {}
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)
distributed_tags = extracted_trace_digest.trace_distributed_tags
unless tracecontext_digest.span_id == extracted_trace_digest.span_id
distributed_tags = distributed_tags&.dup || {}
distributed_tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] =
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`
# Preserve the trace state and last datadog span id
extracted_trace_digest = extracted_trace_digest.merge(
trace_state: tracecontext_digest.trace_state,
trace_state_unknown_fields: tracecontext_digest.trace_state_unknown_fields
trace_state_unknown_fields: tracecontext_digest.trace_state_unknown_fields,
trace_distributed_tags: distributed_tags
)
end
rescue => e
Expand Down

0 comments on commit 0e3a0f1

Please sign in to comment.