Skip to content

feat: Implement strict trace continuation#2872

Draft
giortzisg wants to merge 2 commits intomasterfrom
feat/strict-trace-continuation
Draft

feat: Implement strict trace continuation#2872
giortzisg wants to merge 2 commits intomasterfrom
feat/strict-trace-continuation

Conversation

@giortzisg
Copy link

Description

Implements the strict_trace_continuation feature 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

  • DSN org_id extraction: Parse org ID from the DSN host (e.g., o123.ingest.sentry.io -> "123") using the ORG_ID_REGEX pattern
  • org_id config option: An explicit setting that takes precedence over DSN parsing (useful for self-hosted/Relay setups)
  • strict_trace_continuation config option: Boolean, default false. Controls trace continuation behavior
  • Baggage propagation: Propagate org_id as sentry-org_id in outgoing baggage (both from PropagationContext and Transaction head baggage)
  • Incoming trace validation: Compare incoming sentry-org_id baggage against the SDK's own org ID per the decision matrix

Decision Matrix

Baggage org SDK org strict_trace_continuation Result
1 1 false Continue
None 1 false Continue
1 None false Continue
None None false Continue
1 2 false Start new
1 1 true Continue
None 1 true Start new
1 None true Start new
None None true Continue
1 2 true Start new

Files Modified

  • sentry-ruby/lib/sentry/dsn.rb - org_id extraction from DSN host
  • sentry-ruby/lib/sentry/configuration.rb - org_id, strict_trace_continuation, effective_org_id
  • sentry-ruby/lib/sentry/propagation_context.rb - should_continue_trace? validation + org_id in head baggage
  • sentry-ruby/lib/sentry/transaction.rb - org_id in head baggage
  • sentry-ruby/spec/sentry/dsn_spec.rb - Tests for org_id parsing and override
  • sentry-ruby/spec/sentry/propagation_context_spec.rb - Tests for full decision matrix

Reference Implementations

Closes #2865

🤖 Generated with Claude Code

giortzisg and others added 2 commits February 27, 2026 12:11
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 dingsdax requested review from sl0thentr0py and solnic and removed request for sl0thentr0py February 27, 2026 11:56
#
# @param incoming_baggage [Baggage] the baggage from the incoming request
# @return [Boolean]
def self.should_continue_trace?(incoming_baggage)
Copy link
Contributor

@dingsdax dingsdax Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

Implement strict trace continuation

2 participants