feat: Add strict trace continuation support#1016
Draft
Conversation
Extract org_id from DSN host (e.g., o1234.ingest.sentry.io -> "1234") and propagate it as sentry-org_id in outgoing baggage headers. Validate incoming traces against the SDK's org_id to prevent cross-organization trace mixing. New configuration options: - :org_id - explicit org ID override for self-hosted/Relay setups - :strict_trace_continuation - when true, both org IDs must be present and match to continue a trace (default: false) Closes #1005 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
solnic
requested changes
Mar 11, 2026
Collaborator
solnic
left a comment
There was a problem hiding this comment.
This also requires a high level integration test.
| carrier = setter.(@sentry_trace_key, sentry_trace_header, carrier) | ||
|
|
||
| baggage_value = :otel_ctx.get_value(ctx, @sentry_baggage_ctx_key, :not_found) | ||
| baggage_value = ensure_org_id_in_baggage(baggage_value) |
Collaborator
There was a problem hiding this comment.
This should just try to extract it already, instead of checking if the string is present and then parsing/extracting.
| Tracer.set_current_span(ctx, remote_span_ctx) | ||
| Tracer.set_current_span(ctx, remote_span_ctx) | ||
| else | ||
| require Logger |
Collaborator
There was a problem hiding this comment.
This must be in the module module at the top, not inside the function.
| Tracer.set_current_span(ctx, remote_span_ctx) | ||
| else | ||
| require Logger | ||
| Logger.debug("[Sentry] Not continuing trace due to org ID mismatch") |
Collaborator
There was a problem hiding this comment.
Suggested change
| Logger.debug("[Sentry] Not continuing trace due to org ID mismatch") | |
| Logger.warning("[Sentry] Not continuing trace due to org ID mismatch") |
Collaborator
There was a problem hiding this comment.
Probably including the other org id could be useful?
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.
Summary
o1234.ingest.sentry.io→"1234") and propagate assentry-org_idin outgoing baggage headers:org_idconfig option for explicit override (self-hosted/Relay setups):strict_trace_continuationconfig option (defaultfalse) — when enabled, both org IDs must be present and matchDecision Matrix
Changes
lib/sentry/dsn.ex— org ID extraction from host using^o(\d+)\.regexlib/sentry/config.ex—:org_id,:strict_trace_continuationoptions +effective_org_id/0lib/sentry/opentelemetry/propagator.ex—sentry-org_idin baggage inject/extract +should_continue_trace?/1test/sentry/strict_trace_continuation_test.exs— DSN extraction, config, and full decision matrix tests (12 cases)Test plan
Closes #1005
🤖 Generated with Claude Code