Skip to content

fix(otel): Continue the incoming trace in OTEL spans - #1443

Open
sentry-junior[bot] wants to merge 2 commits into
fix/1441-otel-inject-sentry-tracefrom
fix/1441-otel-adopt-incoming-trace
Open

sentry-junior[bot] wants to merge 2 commits into
fix/1441-otel-inject-sentry-tracefrom
fix/1441-otel-adopt-incoming-trace

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1442.

SentryPropagator::extract_with_context only stored the incoming sentry-trace header for SentrySpanProcessor, so OTEL gave the spans of a continued trace a new trace ID. The Sentry spans used the incoming trace ID, so OTEL and Sentry disagreed on the trace ID of the same span, e.g. for other OTEL exporters or for logs correlated by OTEL trace ID.

extract_with_context now also sets a remote OTEL span context with the incoming trace and span IDs. The remote span is always marked as sampled, so OTEL records the spans and Sentry makes the sampling decision. Copying the incoming sampled flag instead would let OTEL's default ParentBased sampler drop the spans of unsampled traces, which unlinks errors from the incoming trace. The OTEL propagators of the Python, Ruby, Go, and Java SDKs also mark the remote span as sampled.

This adds the public TracePropagationContext::trace_id and TracePropagationContext::span_id getters to sentry-core.

Reproduction: getsentry/repro#96

References #1441

via @szokeasaurusrex.

--

View Session [Sentry]

`SentryPropagator::extract_with_context` only stored the incoming `sentry-trace` header for `SentrySpanProcessor`, so OTEL gave the spans of a continued trace a new trace ID. The Sentry spans used the incoming trace ID, so OTEL and Sentry disagreed on the trace ID of the same span, e.g. for other OTEL exporters or for logs correlated by OTEL trace ID.

`extract_with_context` now also sets a remote OTEL span context with the incoming trace and span IDs. The remote span is always marked as sampled, so OTEL records the spans and Sentry makes the sampling decision. Copying the incoming sampled flag instead would let OTEL's default `ParentBased` sampler drop the spans of unsampled traces, which unlinks errors from the incoming trace. The OTEL propagators of the Python, Ruby, Go, and Java SDKs also mark the remote span as sampled.

This adds the public `TracePropagationContext::trace_id` and `TracePropagationContext::span_id` getters to `sentry-core`.

Reproduction: getsentry/repro#96

References #1441

Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
@sentry-junior
sentry-junior Bot requested a review from a team as a code owner December 1, 2026 15:17
@sentry-junior
sentry-junior Bot added this pull request to stack #1444 December 1, 2026 15:17
Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant