Conversation
Add org ID validation to distributed trace continuation to prevent traces from being continued across different Sentry organizations. - Parse org ID from DSN host (e.g., o1.ingest.us.sentry.io -> "1") - Add OrgId option to SentryOptions to override DSN-parsed value - Add StrictTraceContinuation bool option (default false) - Propagate sentry-org_id in outgoing baggage via DynamicSamplingContext - Validate org IDs in Hub.ContinueTrace: - Mismatched org IDs always start new trace (regardless of setting) - Missing incoming org_id + strict=true -> start new trace - Missing incoming org_id + strict=false -> continue trace (default) - Add comprehensive tests for all org ID validation scenarios - Update API approval snapshots Closes #4963 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Breaking Changes 🛠
Features ✨
Fixes 🐛
Dependencies ⬆️Deps
Other
🤖 This preview updates automatically when you update the PR. |
|
…ion to CreateFromHeaders - Add CHANGELOG.md entry for strict trace continuation feature (#4981) - Fix CS8632 build error by adding #nullable enable before test methods using string? parameters in HubTests.cs - Add org ID mismatch validation directly in SentryPropagationContext.CreateFromHeaders so it starts a new trace when SDK and baggage org IDs don't match - Pass effective org ID from Hub.ContinueTrace to CreateFromHeaders - Add CreateFromHeaders_WithOrgMismatch_StartsNewTrace and CreateFromHeaders_WithOrgMatch_ContinuesTrace tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@giortzisg I've added some context to AGENTS.md in #5035, which should give the agent enough context to be able to correct this PR (once that's been merged into main/this PR). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4981 +/- ##
==========================================
+ Coverage 74.03% 74.07% +0.04%
==========================================
Files 499 499
Lines 18044 18100 +56
Branches 3510 3527 +17
==========================================
+ Hits 13358 13408 +50
- Misses 3830 3832 +2
- Partials 856 860 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@giortzisg / @Flash0ver this looks good to me. OK to merge? |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| logger?.LogInfo("Org ID mismatch (SDK: {0}, baggage: {1}). Starting new trace.", sdkOrgId, baggageOrgId); | ||
| return new SentryPropagationContext(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Duplicate org ID validation creates inconsistent defense layers
Medium Severity
The org ID mismatch check in CreateFromHeaders duplicates logic already in Hub.ShouldContinueTrace(). Since CreateFromHeaders is only called from Hub.ContinueTrace() (confirmed by grep), and the Hub already nulls both headers when validation fails, this check is unreachable dead code in practice. Worse, the CreateFromHeaders version is incomplete — it handles only the mismatch case but not StrictTraceContinuation scenarios (missing org IDs). This inconsistency creates maintenance risk if one check is updated without the other, and could mislead developers into thinking CreateFromHeaders provides complete org ID validation.


Summary
Implements strict trace continuation to validate org IDs in distributed traces, preventing trace continuation from unknown third-party services.
org_idfrom DSN host (e.g.,o1inhttps://key@o1.ingest.us.sentry.io/123yields org ID"1")OrgIdconfig option to manually override DSN-parsed valueStrictTraceContinuationbool config option (defaultfalse)sentry-org_idin outgoing baggage viaDynamicSamplingContextHub.ContinueTrace():StrictTraceContinuation: true-> start new traceStrictTraceContinuation: false-> continue trace (default behavior)Changes
Source files:
src/Sentry/Dsn.cs- Parse org ID from DSN host subdomainsrc/Sentry/SentryOptions.cs- AddStrictTraceContinuationandOrgIdoptions,GetEffectiveOrgId()helpersrc/Sentry/DynamicSamplingContext.cs- Addorg_idto outgoing baggage in all DSC factory methodssrc/Sentry/Internal/Hub.cs- AddShouldContinueTrace()validation logic inContinueTrace()Test files:
test/Sentry.Tests/Protocol/DsnTests.cs- Tests for DSN org ID parsingtest/Sentry.Tests/HubTests.cs- Comprehensive[Theory]tests for all org ID validation scenariosSnapshot files:
OrgIdandStrictTraceContinuationpropertiesReferences
strictTraceContinuationsentry-javascript#16313Closes #4963