Skip to content

feat: Add strict trace continuation support#1016

Merged
solnic merged 14 commits intomasterfrom
feat/strict-trace-continuation
Apr 10, 2026
Merged

feat: Add strict trace continuation support#1016
solnic merged 14 commits intomasterfrom
feat/strict-trace-continuation

Conversation

@giortzisg
Copy link
Copy Markdown
Contributor

@giortzisg giortzisg commented Mar 11, 2026

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

solnic
solnic previously requested changes Mar 11, 2026
Copy link
Copy Markdown
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.

giortzisg and others added 2 commits April 8, 2026 19:14
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@solnic solnic force-pushed the feat/strict-trace-continuation branch from dc8798d to 85b0a4a Compare April 8, 2026 19:14
@solnic solnic force-pushed the feat/strict-trace-continuation branch from 3b6f426 to 1a7a3ac Compare April 9, 2026 07:05
@solnic solnic marked this pull request as ready for review April 9, 2026 07:11
@solnic solnic self-requested a review April 9, 2026 07:12
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7691303. Configure here.

solnic and others added 6 commits April 9, 2026 08:18
- Add `requireEnv()` helper in playwright.config.ts that throws when a
  required env var is missing to make configuration errors explicit
- Use `??=` to set local dev defaults (localhost ports) before validation
  so `npx playwright test` works out of the box without env vars
- Hoist PHOENIX_URL to file scope in tracing.spec.ts with an explicit
  throw, removing the per-describe fallback declarations
- Replace the hardcoded 'http://localhost:4000' URL inside page.evaluate
  with the file-scoped PHOENIX_URL constant

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add three end-to-end Playwright specs covering the strict trace
continuation feature:

1. Matching org_id in baggage → incoming trace_id is preserved
2. Mismatched org_id in baggage → new trace_id is started
3. No org_id in baggage with strict=false → incoming trace_id is preserved

Supporting changes:
- Pass SENTRY_ORG_ID=123 via the webServer command in playwright.config.ts
  so the Phoenix app starts with an org ID configured
- Read SENTRY_ORG_ID and SENTRY_STRICT_TRACE env vars in
  phoenix_app/config/runtime.exs when SENTRY_E2E_TEST_MODE=true

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… org_id

Adds a 4th E2E spec covering the strict mode path where baggage carries
no sentry-org_id: with strict_trace_continuation=true a new trace must
be started rather than continuing the incoming one.

To enable per-test config toggling without a second server, adds a
PUT /sentry-test-config endpoint to the Phoenix app that calls
Sentry.put_config/2 for an allowlist of keys. A test.afterEach hook
resets strict_trace_continuation back to false after every test so the
setting cannot bleed between specs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…orkflow

The strict trace continuation specs require the Phoenix app to have an
org ID configured so that mismatched/missing org IDs in incoming baggage
are correctly rejected. The webServer block in playwright.config.ts
already passes SENTRY_ORG_ID=123, but when SENTRY_E2E_SERVERS_RUNNING=true
that block is skipped and the server is started directly by CI - without
the env var, causing all rejection-path specs to fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… baggage

When incoming baggage contains a sentry-org_id= entry with an empty
value, extract_baggage_org_id/1 correctly returns nil (treating it as
absent). However, ensure_org_id_in_baggage/1 then appended a second
sentry-org_id=<sdk_value> entry, producing a duplicate key. A W3C
baggage parser on a downstream service would pick up the first (empty)
entry and ignore the valid one.

Fix by stripping any empty-valued sentry-org_id entries before appending
the SDK org ID, avoiding duplicate keys entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@solnic solnic dismissed their stale review April 9, 2026 09:42

all good now

@dingsdax dingsdax self-requested a review April 10, 2026 10:47
@solnic solnic merged commit 48b9c5c into master Apr 10, 2026
11 checks passed
@solnic solnic deleted the feat/strict-trace-continuation branch April 10, 2026 21:59
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)

3 participants