Skip to content

fix(tracing): Ignore sentry-trace headers without a trace_id - #3188

Merged
sl0thentr0py merged 1 commit into
masterfrom
fix/sentry-trace-require-trace-id
Nov 5, 2026
Merged

sl0thentr0py merged 1 commit into
masterfrom
fix/sentry-trace-require-trace-id

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

SENTRY_TRACE_REGEXP makes every group optional. That means a header like -1 parses to [nil, nil, true]: no trace ID, no parent span ID, but parent_sampled = true. Without a custom traces_sampler, that value overrides traces_sample_rate and forces sampling on. -0 forces it off. The SDK also treats the request as a continued trace and freezes an empty DSC.

extract_sentry_trace now returns nil when it captured no trace ID, so these headers are ignored the same way as a missing header. This matches sentry-javascript, where propagationContextFromHeaders starts a new trace when traceId is missing. Well-formed headers still pass parent_sampled through as before. The OpenTelemetry propagator already handles a nil result.

This is parser hardening, not a security fix, because a well-formed sampled header can still set the sampling decision on purpose. Reproduction: getsentry/repro, branch repro/sentry-ruby-malformed-trace-header-sampling.

Refs SDK-1223

via @dingsdax.

--

View Session [Sentry]

SENTRY_TRACE_REGEXP makes every group optional, so headers such as "-1"
parsed to [nil, nil, true] and set parent_sampled, which overrides
traces_sample_rate. Return nil when no trace_id was captured so these
headers are ignored, matching sentry-javascript.

Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>
@linear-code

linear-code Bot commented Nov 5, 2026

Copy link
Copy Markdown

SDK-1223

@sl0thentr0py
sl0thentr0py merged commit a62cf84 into master Nov 5, 2026
157 checks passed
@sl0thentr0py
sl0thentr0py deleted the fix/sentry-trace-require-trace-id branch November 5, 2026 11:48
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.

2 participants