Repository navigation
fix(tracing): Ignore sentry-trace headers without a trace_id - #3188
Merged
Merged
Conversation
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>
sl0thentr0py
approved these changes
Nov 5, 2026
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SENTRY_TRACE_REGEXPmakes every group optional. That means a header like-1parses to[nil, nil, true]: no trace ID, no parent span ID, butparent_sampled = true. Without a customtraces_sampler, that value overridestraces_sample_rateand forces sampling on.-0forces it off. The SDK also treats the request as a continued trace and freezes an empty DSC.extract_sentry_tracenow returnsnilwhen it captured no trace ID, so these headers are ignored the same way as a missing header. This matches sentry-javascript, wherepropagationContextFromHeadersstarts a new trace whentraceIdis missing. Well-formed headers still passparent_sampledthrough as before. The OpenTelemetry propagator already handles anilresult.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]