feat: Add strict trace continuation support#5136
Conversation
Extract org ID from DSN host, add strictTraceContinuation and orgId options, propagate sentry-org_id in baggage, and validate incoming traces per the decision matrix. Closes #5128
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
🤖 This preview updates automatically when you update the PR. |
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 310.68 ms | 359.24 ms | 48.56 ms |
| e59e22a | 368.02 ms | 432.00 ms | 63.98 ms |
| fc5ccaf | 279.11 ms | 353.34 ms | 74.23 ms |
| d15471f | 315.20 ms | 370.22 ms | 55.02 ms |
| d15471f | 286.65 ms | 314.68 ms | 28.03 ms |
| d15471f | 342.08 ms | 415.44 ms | 73.35 ms |
| ad8da22 | 314.38 ms | 352.29 ms | 37.91 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
| abfcc92 | 309.54 ms | 380.32 ms | 70.78 ms |
| 91bb874 | 314.47 ms | 440.00 ms | 125.53 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
| e59e22a | 1.58 MiB | 2.20 MiB | 635.34 KiB |
| fc5ccaf | 1.58 MiB | 2.13 MiB | 557.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
| abfcc92 | 1.58 MiB | 2.13 MiB | 557.31 KiB |
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
Add public API declarations for new org ID and strict trace continuation methods on Baggage, PropagationContext, and SentryOptions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| fun `strict=false, mismatched orgs - starts new trace`() { | ||
| val options = makeOptions(dsnOrgId = "2", strict = false) | ||
| val pc = | ||
| PropagationContext.fromHeaders( |
There was a problem hiding this comment.
invocations expect a wrong signature; in the future we should make sure to compile test sources and tests pass
| final @NotNull ILogger logger, | ||
| final @Nullable String sentryTraceHeaderString, | ||
| final @Nullable List<String> baggageHeaderStrings) { | ||
| return fromHeaders(logger, sentryTraceHeaderString, baggageHeaderStrings, null); |
There was a problem hiding this comment.
We could use Sentry.getCurrentScopes().getOptions() here to default to the current options.
The better fix would probably be to replace call sites with passing in options and remove this overload.
Since PropagationContext is marked internal, we're free to change / replace / remove methods.
| } | ||
| } | ||
|
|
||
| public static @NotNull PropagationContext fromHeaders( |
There was a problem hiding this comment.
This overload isn't covered. This means our OpenTelemetry integrations would not check orgId.
| * When false, a mismatch between present org IDs will still start a new trace, but missing org | ||
| * IDs on either side are tolerated. | ||
| */ | ||
| private boolean strictTraceContinuation = false; |
There was a problem hiding this comment.
We should add both of these options to ExternalOptions and ManifestMetadataReader as well.
There's no tests for options.
We have https://github.com/getsentry/sentry-java/blob/main/.cursor/rules/options.mdc which explains details around options in this SDK.
| private final @Nullable String secretKey; | ||
| private final @NotNull String publicKey; | ||
| private final @NotNull URI sentryUri; | ||
| private @Nullable String orgId; |
| return orgId; | ||
| } | ||
|
|
||
| void setOrgId(final @Nullable String orgId) { |
|
|
||
| ### Features | ||
|
|
||
| - Add strict trace continuation support ([#5136](https://github.com/getsentry/sentry-java/pull/5136)) |
There was a problem hiding this comment.
We should add some description here for customers to explain what this means for them.
We should also mention the new options.
Summary
o123.ingest.sentry.io→"123")strictTraceContinuation(boolean, default false) andorgId(String) options toSentryOptionssentry-org_idin baggage / Dynamic Sampling ContextDecision Matrix
Changes
Dsn.java— org ID extraction from host using^o(\d+)\.regexSentryOptions.java—strictTraceContinuation,orgId, andgetEffectiveOrgId()Baggage.java—ORG_IDDSCKey, getter/setter, population insetValuesFromTransaction/setValuesFromScope/fromEventPropagationContext.java—shouldContinueTrace()logic infromHeaders()Scopes.java— pass options tofromHeaders()Test plan
Closes #5128
🤖 Generated with Claude Code