Skip to content

feat: Add strict trace continuation support#5136

Draft
giortzisg wants to merge 8 commits intomainfrom
feat/strict-trace-continuation
Draft

feat: Add strict trace continuation support#5136
giortzisg wants to merge 8 commits intomainfrom
feat/strict-trace-continuation

Conversation

@giortzisg
Copy link

Summary

  • Extract org ID from DSN host (e.g., o123.ingest.sentry.io"123")
  • Add strictTraceContinuation (boolean, default false) and orgId (String) options to SentryOptions
  • Propagate sentry-org_id in baggage / Dynamic Sampling Context
  • Validate incoming traces per the decision matrix (mismatched org → new trace; strict mode rejects missing org)

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

  • Dsn.java — org ID extraction from host using ^o(\d+)\. regex
  • SentryOptions.javastrictTraceContinuation, orgId, and getEffectiveOrgId()
  • Baggage.javaORG_ID DSCKey, getter/setter, population in setValuesFromTransaction/setValuesFromScope/fromEvent
  • PropagationContext.javashouldContinueTrace() logic in fromHeaders()
  • Scopes.java — pass options to fromHeaders()

Test plan

  • DSN org ID extraction tests (5 cases)
  • PropagationContext decision matrix tests (10 cases)

Closes #5128

🤖 Generated with Claude Code

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add strict trace continuation support by giortzisg in #5136

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 61ada6a

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 309.58 ms 363.22 ms 53.64 ms
Size 1.58 MiB 2.29 MiB 723.51 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
91bb874 314.47 ms 440.00 ms 125.53 ms
dba088c 333.98 ms 381.16 ms 47.18 ms
d15471f 310.66 ms 368.19 ms 57.53 ms
bbc35bb 298.53 ms 372.17 ms 73.64 ms
d15471f 307.28 ms 381.85 ms 74.57 ms
ad8da22 362.98 ms 453.94 ms 90.96 ms
cf708bd 408.35 ms 458.98 ms 50.63 ms
96449e8 361.30 ms 423.39 ms 62.09 ms
27d7cf8 309.43 ms 364.27 ms 54.85 ms
91bb874 311.00 ms 363.47 ms 52.47 ms

App size

Revision Plain With Sentry Diff
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
dba088c 1.58 MiB 2.13 MiB 558.99 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 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
96449e8 1.58 MiB 2.11 MiB 539.35 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB

Previous results on branch: feat/strict-trace-continuation

Startup times

Revision Plain With Sentry Diff
79a9407 348.85 ms 428.10 ms 79.25 ms

App size

Revision Plain With Sentry Diff
79a9407 1.58 MiB 2.29 MiB 723.70 KiB

fun `strict=false, mismatched orgs - starts new trace`() {
val options = makeOptions(dsnOrgId = "2", strict = false)
val pc =
PropagationContext.fromHeaders(
Copy link
Member

Choose a reason for hiding this comment

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

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);
Copy link
Member

Choose a reason for hiding this comment

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

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(
Copy link
Member

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

This should be final

return orgId;
}

void setOrgId(final @Nullable String orgId) {
Copy link
Member

Choose a reason for hiding this comment

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

No setter needed here.


### Features

- Add strict trace continuation support ([#5136](https://github.com/getsentry/sentry-java/pull/5136))
Copy link
Member

Choose a reason for hiding this comment

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

We should add some description here for customers to explain what this means for them.
We should also mention the new options.

giortzisg and others added 6 commits March 4, 2026 14:01
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
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>
- Make Dsn.orgId final, remove unnecessary setter
- Fix test signatures to use List<String> for baggage headers
- Add strictTraceContinuation and orgId to ExternalOptions and merge()
- Add options to ManifestMetadataReader for Android manifest config
- Use Sentry.getCurrentScopes().getOptions() in legacy fromHeaders overload
- Improve CHANGELOG description with details about new options
- Update API surface file for ExternalOptions changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add comment to empty catch block in PropagationContext to satisfy -Werror
- Add setOrgId setter to Dsn class (remove final modifier on orgId field) to
  support the existing test for org ID override

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@giortzisg giortzisg force-pushed the feat/strict-trace-continuation branch from 457e177 to e30064c Compare March 4, 2026 13:14
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