Skip to content

feat: Add strict trace continuation support#1016

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

feat: Add strict trace continuation support#1016
giortzisg wants to merge 2 commits intomasterfrom
feat/strict-trace-continuation

Conversation

@giortzisg
Copy link

Summary

  • Extract org ID from DSN host (e.g., o1234.ingest.sentry.io"1234") and propagate as sentry-org_id in outgoing baggage headers
  • Validate incoming traces against the SDK's org ID to prevent cross-organization trace mixing
  • Add :org_id config option for explicit override (self-hosted/Relay setups)
  • Add :strict_trace_continuation config option (default false) — when enabled, both org IDs must be present and match

Decision Matrix

Baggage org SDK org strict=false strict=true
1 1 Continue Continue
None 1 Continue New trace
1 None Continue New trace
None None Continue Continue
1 2 New trace New trace

Changes

  • lib/sentry/dsn.ex — org ID extraction from host using ^o(\d+)\. regex
  • lib/sentry/config.ex:org_id, :strict_trace_continuation options + effective_org_id/0
  • lib/sentry/opentelemetry/propagator.exsentry-org_id in baggage inject/extract + should_continue_trace?/1
  • test/sentry/strict_trace_continuation_test.exs — DSN extraction, config, and full decision matrix tests (12 cases)

Test plan

  • DSN org ID extraction tests (5 cases)
  • Config option default and override tests (4 cases)
  • effective_org_id precedence tests (4 cases)
  • Decision matrix tests (10 cases + 2 edge cases)
  • CI validation

Closes #1005

🤖 Generated with Claude Code

giortzisg and others added 2 commits March 11, 2026 11:56
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]>
Copy link
Collaborator

@solnic solnic left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Logger.debug("[Sentry] Not continuing trace due to org ID mismatch")
Logger.warning("[Sentry] Not continuing trace due to org ID mismatch")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably including the other org id could be useful?

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 (org_id validation)

2 participants