Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dc8d319
feat: Add strict trace continuation support
giortzisg Mar 2, 2026
e550ae3
Format code
getsentry-bot Mar 2, 2026
c272ee4
Add changelog entry
giortzisg Mar 2, 2026
1cfc2ea
Update API surface file for strict trace continuation
giortzisg Mar 3, 2026
108eb2d
Address review comments for strict trace continuation
giortzisg Mar 4, 2026
e30064c
Fix compilation errors after rebase on main
giortzisg Mar 4, 2026
4545735
fix: Move changelog entry to Unreleased section
giortzisg Mar 4, 2026
61ada6a
Format code
getsentry-bot Mar 4, 2026
519f6a6
fix: Address review comments — pass options to PropagationContext, fi…
giortzisg Mar 9, 2026
360fc94
fix: Add missing 8.34.1 changelog section
giortzisg Mar 9, 2026
ea9f456
merge: Resolve changelog conflict with main
giortzisg Mar 9, 2026
58bfc8e
Format code
getsentry-bot Mar 9, 2026
ebe8c4c
fix: Address PR review comments for strict trace continuation
giortzisg Mar 11, 2026
824b30b
Format code
getsentry-bot Mar 11, 2026
e2fdc46
fix(tracing): Clarify strict org validation debug log
adinauer Mar 20, 2026
d3b073d
fix(android): Use enabled suffix for strict trace manifest key
adinauer Mar 20, 2026
f7fef22
fix(api): Mark effective org ID helper as internal
adinauer Mar 20, 2026
71562fa
ref(tracing): Extract trace continuation decision into TracingUtils
adinauer Mar 23, 2026
327d897
fix(opentelemetry): Enforce strict continuation in propagators
adinauer Mar 23, 2026
f1edc98
Merge branch 'main' into feat/strict-trace-continuation
adinauer Mar 23, 2026
863f05b
Format code
getsentry-bot Mar 23, 2026
1d8e301
fix(tracing): Fix empty orgId bypassing DSN fallback
adinauer Mar 26, 2026
25e71db
Merge branch 'main' into feat/strict-trace-continuation
adinauer Mar 26, 2026
a3c86e7
Format code
getsentry-bot Mar 26, 2026
3d1d119
ref: Remove redundant trim of already-trimmed effective org ID
adinauer Mar 27, 2026
bad469f
Merge branch 'main' into feat/strict-trace-continuation
adinauer Mar 30, 2026
cf7d9fe
ref(tracing): Revert shouldContinueTrace check in OtelSentrySpanProce…
adinauer Mar 30, 2026
435d2e7
fix(test): Clean up global Sentry state in SentryPropagatorTest
adinauer Mar 30, 2026
63222e5
fix(test): Use mock scopes in propagator strict continuation tests
adinauer Mar 30, 2026
a4cd81a
fix(test): Reset OTel context in propagator test teardown
adinauer Mar 30, 2026
f029100
Merge branch 'main' into feat/strict-trace-continuation
adinauer Mar 30, 2026
070ee32
fix(test): Add back test for inject with invalid span
adinauer Mar 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ref(tracing): Extract trace continuation decision into TracingUtils
Move strict trace continuation org-id validation logic to TracingUtils
so it can be reused by tracing entry points.

Update PropagationContext to call the shared helper and add dedicated
TracingUtils tests for strict/non-strict org-id continuation outcomes.

Co-Authored-By: Claude <noreply@anthropic.com>
  • Loading branch information
adinauer and claude committed Mar 23, 2026
commit 71562fa460e34394c1deb26ec29efa362e56bdd2
28 changes: 1 addition & 27 deletions sentry/src/main/java/io/sentry/PropagationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static PropagationContext fromHeaders(
final @Nullable Baggage baggage,
final @Nullable SpanId spanId,
final @Nullable SentryOptions options) {
if (options != null && !shouldContinueTrace(options, baggage)) {
if (options != null && !TracingUtils.shouldContinueTrace(options, baggage)) {
options
.getLogger()
.log(
Expand Down Expand Up @@ -163,30 +163,4 @@ public void setSampled(final @Nullable Boolean sampled) {
return sampleRand == null ? 0.0 : sampleRand;
}

static boolean shouldContinueTrace(
final @NotNull SentryOptions options, final @Nullable Baggage baggage) {
final @Nullable String rawSdkOrgId = options.getEffectiveOrgId();
final @Nullable String sdkOrgId =
(rawSdkOrgId != null && !rawSdkOrgId.trim().isEmpty()) ? rawSdkOrgId.trim() : null;
final @Nullable String rawBaggageOrgId = baggage != null ? baggage.getOrgId() : null;
final @Nullable String baggageOrgId =
(rawBaggageOrgId != null && !rawBaggageOrgId.trim().isEmpty())
? rawBaggageOrgId.trim()
: null;

// Mismatched org IDs always reject regardless of strict mode
if (sdkOrgId != null && baggageOrgId != null && !sdkOrgId.equals(baggageOrgId)) {
return false;
}

// In strict mode, both must be present and match (unless both are missing)
if (options.isStrictTraceContinuation()) {
if (sdkOrgId == null && baggageOrgId == null) {
return true;
}
return sdkOrgId != null && sdkOrgId.equals(baggageOrgId);
}

return true;
}
}
28 changes: 28 additions & 0 deletions sentry/src/main/java/io/sentry/util/TracingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ public static boolean isIgnored(
return false;
}

@ApiStatus.Internal
public static boolean shouldContinueTrace(
final @NotNull SentryOptions options, final @Nullable Baggage baggage) {
final @Nullable String rawSdkOrgId = options.getEffectiveOrgId();
final @Nullable String sdkOrgId =
(rawSdkOrgId != null && !rawSdkOrgId.trim().isEmpty()) ? rawSdkOrgId.trim() : null;
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
final @Nullable String rawBaggageOrgId = baggage != null ? baggage.getOrgId() : null;
final @Nullable String baggageOrgId =
(rawBaggageOrgId != null && !rawBaggageOrgId.trim().isEmpty())
? rawBaggageOrgId.trim()
: null;

// Mismatched org IDs always reject regardless of strict mode
if (sdkOrgId != null && baggageOrgId != null && !sdkOrgId.equals(baggageOrgId)) {
return false;
}

// In strict mode, both must be present and match (unless both are missing)
if (options.isStrictTraceContinuation()) {
if (sdkOrgId == null && baggageOrgId == null) {
return true;
}
return sdkOrgId != null && sdkOrgId.equals(baggageOrgId);
}

return true;
}

/**
* Ensures a non null baggage instance is present by creating a new Baggage instance if null is
* passed in.
Expand Down
56 changes: 56 additions & 0 deletions sentry/src/test/java/io/sentry/util/TracingUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,60 @@ class TracingUtilsTest {
assertEquals(fixture.scope.propagationContext.spanId.toString(), parts[2])
assertEquals("00", parts[3])
}

private fun makeOptions(
dsnOrgId: String?,
explicitOrgId: String? = null,
strict: Boolean = false,
): SentryOptions {
val options = SentryOptions()
if (dsnOrgId != null) {
options.dsn = "https://key@o$dsnOrgId.ingest.sentry.io/123"
} else {
options.dsn = "https://key@sentry.io/123"
}
options.orgId = explicitOrgId
options.isStrictTraceContinuation = strict
return options
}

private fun makeBaggage(orgId: String?): Baggage {
val raw =
if (orgId != null) {
"sentry-trace_id=bc6d53f15eb88f4320054569b8c553d4,sentry-org_id=$orgId"
} else {
"sentry-trace_id=bc6d53f15eb88f4320054569b8c553d4"
}
return Baggage.fromHeader(raw, NoOpLogger.getInstance())
}

@Test
fun `shouldContinueTrace strict=false matching org ids returns true`() {
val options = makeOptions(dsnOrgId = "1", strict = false)
assertTrue(TracingUtils.shouldContinueTrace(options, makeBaggage("1")))
}

@Test
fun `shouldContinueTrace strict=false mismatched org ids returns false`() {
val options = makeOptions(dsnOrgId = "2", strict = false)
assertFalse(TracingUtils.shouldContinueTrace(options, makeBaggage("1")))
}

@Test
fun `shouldContinueTrace strict=true matching org ids returns true`() {
val options = makeOptions(dsnOrgId = "1", strict = true)
assertTrue(TracingUtils.shouldContinueTrace(options, makeBaggage("1")))
}

@Test
fun `shouldContinueTrace strict=true missing baggage org id returns false`() {
val options = makeOptions(dsnOrgId = "1", strict = true)
assertFalse(TracingUtils.shouldContinueTrace(options, makeBaggage(null)))
}

@Test
fun `shouldContinueTrace strict=true both missing org ids returns true`() {
val options = makeOptions(dsnOrgId = null, strict = true)
assertTrue(TracingUtils.shouldContinueTrace(options, makeBaggage(null)))
}
}