Skip to content

Commit 455f13a

Browse files
authored
Merge ea9f456 into 08ffa5a
2 parents 08ffa5a + ea9f456 commit 455f13a

23 files changed

Lines changed: 539 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Prevent cross-organization trace continuation ([#5136](https://github.com/getsentry/sentry-java/pull/5136))
8+
- By default, the SDK now extracts the organization ID from the DSN (e.g. `o123.ingest.sentry.io`) and compares it with the `sentry-org_id` value in incoming baggage headers. When the two differ, the SDK starts a fresh trace instead of continuing the foreign one. This guards against accidentally linking traces across organizations.
9+
- New option `strictTraceContinuation` (default `false`): when enabled, both the SDK's org ID **and** the incoming baggage org ID must be present and match for a trace to be continued. Traces with a missing org ID on either side are rejected.
10+
- New option `orgId`: allows explicitly setting the organization ID for self-hosted and Relay setups where it cannot be extracted from the DSN. Configurable via code, `sentry.properties` (`org-id`), or Android manifest (`io.sentry.org-id`).
11+
312
## 8.34.1
413

514
### Fixes

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ final class ManifestMetadataReader {
167167

168168
static final String FEEDBACK_SHOW_BRANDING = "io.sentry.feedback.show-branding";
169169

170+
static final String STRICT_TRACE_CONTINUATION = "io.sentry.strict-trace-continuation";
171+
static final String ORG_ID = "io.sentry.org-id";
172+
170173
static final String SPOTLIGHT_ENABLE = "io.sentry.spotlight.enable";
171174

172175
static final String SPOTLIGHT_CONNECTION_URL = "io.sentry.spotlight.url";
@@ -662,6 +665,15 @@ static void applyMetadata(
662665
feedbackOptions.setShowBranding(
663666
readBool(metadata, logger, FEEDBACK_SHOW_BRANDING, feedbackOptions.isShowBranding()));
664667

668+
options.setStrictTraceContinuation(
669+
readBool(
670+
metadata, logger, STRICT_TRACE_CONTINUATION, options.isStrictTraceContinuation()));
671+
672+
final @Nullable String orgId = readString(metadata, logger, ORG_ID, null);
673+
if (orgId != null) {
674+
options.setOrgId(orgId);
675+
}
676+
665677
options.setEnableSpotlight(
666678
readBool(metadata, logger, SPOTLIGHT_ENABLE, options.isEnableSpotlight()));
667679

sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,4 +2436,54 @@ class ManifestMetadataReaderTest {
24362436
// maskAllImages should also add WebView
24372437
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.webkit.WebView"))
24382438
}
2439+
2440+
@Test
2441+
fun `applyMetadata reads strictTraceContinuation and keeps default value if not found`() {
2442+
// Arrange
2443+
val context = fixture.getContext()
2444+
2445+
// Act
2446+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2447+
2448+
// Assert
2449+
assertFalse(fixture.options.isStrictTraceContinuation)
2450+
}
2451+
2452+
@Test
2453+
fun `applyMetadata reads strictTraceContinuation to options`() {
2454+
// Arrange
2455+
val bundle = bundleOf(ManifestMetadataReader.STRICT_TRACE_CONTINUATION to true)
2456+
val context = fixture.getContext(metaData = bundle)
2457+
2458+
// Act
2459+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2460+
2461+
// Assert
2462+
assertTrue(fixture.options.isStrictTraceContinuation)
2463+
}
2464+
2465+
@Test
2466+
fun `applyMetadata reads orgId and keeps null if not found`() {
2467+
// Arrange
2468+
val context = fixture.getContext()
2469+
2470+
// Act
2471+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2472+
2473+
// Assert
2474+
assertNull(fixture.options.orgId)
2475+
}
2476+
2477+
@Test
2478+
fun `applyMetadata reads orgId to options`() {
2479+
// Arrange
2480+
val bundle = bundleOf(ManifestMetadataReader.ORG_ID to "12345")
2481+
val context = fixture.getContext(metaData = bundle)
2482+
2483+
// Act
2484+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2485+
2486+
// Assert
2487+
assertEquals("12345", fixture.options.orgId)
2488+
}
24392489
}

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public SamplingResult shouldSample(
9191
final @NotNull PropagationContext propagationContext =
9292
sentryTraceHeader == null
9393
? new PropagationContext(new SentryId(traceId), randomSpanId, null, baggage, null)
94-
: PropagationContext.fromHeaders(sentryTraceHeader, baggage, randomSpanId);
94+
: PropagationContext.fromHeaders(sentryTraceHeader, baggage, randomSpanId, scopes.getOptions());
9595

9696
final @NotNull TransactionContext transactionContext =
9797
TransactionContext.fromPropagationContext(propagationContext);

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySpanProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri
127127
new SentryId(traceData.getTraceId()), spanId, null, null, null)
128128
: TransactionContext.fromPropagationContext(
129129
PropagationContext.fromHeaders(
130-
traceData.getSentryTraceHeader(), traceData.getBaggage(), spanId));
130+
traceData.getSentryTraceHeader(), traceData.getBaggage(), spanId, scopes.getOptions()));
131131
;
132132
transactionContext.setName(transactionName);
133133
transactionContext.setTransactionNameSource(transactionNameSource);

sentry-spring-7/src/test/kotlin/io/sentry/spring7/tracing/SentryTracingFilterTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SentryTracingFilterTest {
9696
logger,
9797
it.arguments[0] as String?,
9898
it.arguments[1] as List<String>?,
99+
null,
99100
)
100101
)
101102
}

sentry-spring-7/src/test/kotlin/io/sentry/spring7/webflux/SentryWebFluxTracingFilterTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class SentryWebFluxTracingFilterTest {
9898
logger,
9999
it.arguments[0] as String?,
100100
it.arguments[1] as List<String>?,
101+
null,
101102
)
102103
)
103104
}

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/tracing/SentryTracingFilterTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SentryTracingFilterTest {
9696
logger,
9797
it.arguments[0] as String?,
9898
it.arguments[1] as List<String>?,
99+
null,
99100
)
100101
)
101102
}

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebFluxTracingFilterTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class SentryWebFluxTracingFilterTest {
9898
logger,
9999
it.arguments[0] as String?,
100100
it.arguments[1] as List<String>?,
101+
null,
101102
)
102103
)
103104
}

sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTracingFilterTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SentryTracingFilterTest {
9696
logger,
9797
it.arguments[0] as String?,
9898
it.arguments[1] as List<String>?,
99+
null,
99100
)
100101
)
101102
}

0 commit comments

Comments
 (0)