feat: Implement strict trace continuation#2872
Draft
Conversation
Add support for org_id extraction from DSN and strict trace continuation to control whether the SDK continues traces from third-party services. Changes: - Extract org_id from DSN host (e.g., "o123.ingest.sentry.io" -> "123") - Add `org_id` config option to explicitly set the organization ID - Add `strict_trace_continuation` boolean config option (default: false) - Propagate org_id in baggage as `sentry-org_id` - Validate incoming trace org_id against SDK org_id per decision matrix - Add comprehensive tests for all scenarios Closes #2865 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The test DSN uses o447951.ingest.sentry.io, so the new org_id propagation correctly adds sentry-org_id=447951 to baggage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dingsdax
reviewed
Feb 27, 2026
| # | ||
| # @param incoming_baggage [Baggage] the baggage from the incoming request | ||
| # @return [Boolean] | ||
| def self.should_continue_trace?(incoming_baggage) |
Contributor
There was a problem hiding this comment.
this could be more idiomatic imho 🤔
def self.should_continue_trace?(incoming_baggage)
return true unless Sentry.initialized?
configuration = Sentry.configuration
sdk_org_id = configuration.effective_org_id
baggage_org_id = incoming_baggage&.items&.fetch("org_id", nil)
# Always start a new trace if both org IDs are present but don't match
if sdk_org_id && baggage_org_id && sdk_org_id != baggage_org_id
return false
end
# In non-strict mode, continue unless explicitly rejected above
return true unless configuration.strict_trace_continuation
# Strict mode:
# - continue if both are missing
# - otherwise require exact match
return true if sdk_org_id.nil? && baggage_org_id.nil?
sdk_org_id == baggage_org_id
end
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.
Description
Implements the
strict_trace_continuationfeature for the Sentry Ruby SDK. This controls whether the SDK continues traces from unknown third-party services that happen to be instrumented by Sentry.Changes
o123.ingest.sentry.io->"123") using theORG_ID_REGEXpatternorg_idconfig option: An explicit setting that takes precedence over DSN parsing (useful for self-hosted/Relay setups)strict_trace_continuationconfig option: Boolean, defaultfalse. Controls trace continuation behaviorsentry-org_idin outgoing baggage (both fromPropagationContextandTransactionhead baggage)sentry-org_idbaggage against the SDK's own org ID per the decision matrixDecision Matrix
Files Modified
sentry-ruby/lib/sentry/dsn.rb- org_id extraction from DSN hostsentry-ruby/lib/sentry/configuration.rb-org_id,strict_trace_continuation,effective_org_idsentry-ruby/lib/sentry/propagation_context.rb-should_continue_trace?validation + org_id in head baggagesentry-ruby/lib/sentry/transaction.rb- org_id in head baggagesentry-ruby/spec/sentry/dsn_spec.rb- Tests for org_id parsing and overridesentry-ruby/spec/sentry/propagation_context_spec.rb- Tests for full decision matrixReference Implementations
Closes #2865
🤖 Generated with Claude Code