Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Features

- Prevent cross-organization trace continuation ([#5136](https://github.com/getsentry/sentry-java/pull/5136))
- 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.
- 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.
- 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`).

## 8.34.1

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ final class ManifestMetadataReader {

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

static final String STRICT_TRACE_CONTINUATION = "io.sentry.strict-trace-continuation";
static final String ORG_ID = "io.sentry.org-id";

static final String SPOTLIGHT_ENABLE = "io.sentry.spotlight.enable";

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

options.setStrictTraceContinuation(
readBool(
metadata, logger, STRICT_TRACE_CONTINUATION, options.isStrictTraceContinuation()));

final @Nullable String orgId = readString(metadata, logger, ORG_ID, null);
if (orgId != null) {
options.setOrgId(orgId);
}

options.setEnableSpotlight(
readBool(metadata, logger, SPOTLIGHT_ENABLE, options.isEnableSpotlight()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2436,4 +2436,54 @@ class ManifestMetadataReaderTest {
// maskAllImages should also add WebView
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.webkit.WebView"))
}

@Test
fun `applyMetadata reads strictTraceContinuation and keeps default value if not found`() {
// Arrange
val context = fixture.getContext()

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertFalse(fixture.options.isStrictTraceContinuation)
}

@Test
fun `applyMetadata reads strictTraceContinuation to options`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.STRICT_TRACE_CONTINUATION to true)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertTrue(fixture.options.isStrictTraceContinuation)
}

@Test
fun `applyMetadata reads orgId and keeps null if not found`() {
// Arrange
val context = fixture.getContext()

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertNull(fixture.options.orgId)
}

@Test
fun `applyMetadata reads orgId to options`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.ORG_ID to "12345")
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertEquals("12345", fixture.options.orgId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public SamplingResult shouldSample(
final @NotNull PropagationContext propagationContext =
sentryTraceHeader == null
? new PropagationContext(new SentryId(traceId), randomSpanId, null, baggage, null)
: PropagationContext.fromHeaders(sentryTraceHeader, baggage, randomSpanId);
: PropagationContext.fromHeaders(sentryTraceHeader, baggage, randomSpanId, scopes.getOptions());

final @NotNull TransactionContext transactionContext =
TransactionContext.fromPropagationContext(propagationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri
new SentryId(traceData.getTraceId()), spanId, null, null, null)
: TransactionContext.fromPropagationContext(
PropagationContext.fromHeaders(
traceData.getSentryTraceHeader(), traceData.getBaggage(), spanId));
traceData.getSentryTraceHeader(), traceData.getBaggage(), spanId, scopes.getOptions()));
;
transactionContext.setName(transactionName);
transactionContext.setTransactionNameSource(transactionNameSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SentryTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class SentryWebFluxTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SentryTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class SentryWebFluxTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SentryTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class SentryWebFluxTracingFilterTest {
logger,
it.arguments[0] as String?,
it.arguments[1] as List<String>?,
null,
)
)
}
Expand Down
18 changes: 15 additions & 3 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class io/sentry/Baggage {
public static fun fromHeader (Ljava/util/List;ZLio/sentry/ILogger;)Lio/sentry/Baggage;
public fun get (Ljava/lang/String;)Ljava/lang/String;
public fun getEnvironment ()Ljava/lang/String;
public fun getOrgId ()Ljava/lang/String;
public fun getPublicKey ()Ljava/lang/String;
public fun getRelease ()Ljava/lang/String;
public fun getReplayId ()Ljava/lang/String;
Expand All @@ -62,6 +63,7 @@ public final class io/sentry/Baggage {
public fun isShouldFreeze ()Z
public fun set (Ljava/lang/String;Ljava/lang/String;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setOrgId (Ljava/lang/String;)V
public fun setPublicKey (Ljava/lang/String;)V
public fun setRelease (Ljava/lang/String;)V
public fun setReplayId (Ljava/lang/String;)V
Expand All @@ -81,6 +83,7 @@ public final class io/sentry/Baggage {
public final class io/sentry/Baggage$DSCKeys {
public static final field ALL Ljava/util/List;
public static final field ENVIRONMENT Ljava/lang/String;
public static final field ORG_ID Ljava/lang/String;
public static final field PUBLIC_KEY Ljava/lang/String;
public static final field RELEASE Ljava/lang/String;
public static final field REPLAY_ID Ljava/lang/String;
Expand Down Expand Up @@ -501,6 +504,7 @@ public final class io/sentry/ExternalOptions {
public fun getInAppExcludes ()Ljava/util/List;
public fun getInAppIncludes ()Ljava/util/List;
public fun getMaxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize;
public fun getOrgId ()Ljava/lang/String;
public fun getPrintUncaughtStackTrace ()Ljava/lang/Boolean;
public fun getProfileLifecycle ()Lio/sentry/ProfileLifecycle;
public fun getProfileSessionSampleRate ()Ljava/lang/Double;
Expand Down Expand Up @@ -530,6 +534,7 @@ public final class io/sentry/ExternalOptions {
public fun isGlobalHubMode ()Ljava/lang/Boolean;
public fun isSendDefaultPii ()Ljava/lang/Boolean;
public fun isSendModules ()Ljava/lang/Boolean;
public fun isStrictTraceContinuation ()Ljava/lang/Boolean;
public fun setCaptureOpenTelemetryEvents (Ljava/lang/Boolean;)V
public fun setCron (Lio/sentry/SentryOptions$Cron;)V
public fun setDebug (Ljava/lang/Boolean;)V
Expand All @@ -552,6 +557,7 @@ public final class io/sentry/ExternalOptions {
public fun setIgnoredErrors (Ljava/util/List;)V
public fun setIgnoredTransactions (Ljava/util/List;)V
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
public fun setOrgId (Ljava/lang/String;)V
public fun setPrintUncaughtStackTrace (Ljava/lang/Boolean;)V
public fun setProfileLifecycle (Lio/sentry/ProfileLifecycle;)V
public fun setProfileSessionSampleRate (Ljava/lang/Double;)V
Expand All @@ -568,6 +574,7 @@ public final class io/sentry/ExternalOptions {
public fun setSessionFlushTimeoutMillis (Ljava/lang/Long;)V
public fun setShutdownTimeoutMillis (Ljava/lang/Long;)V
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
public fun setStrictTraceContinuation (Ljava/lang/Boolean;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTracesSampleRate (Ljava/lang/Double;)V
}
Expand Down Expand Up @@ -2269,9 +2276,9 @@ public final class io/sentry/PropagationContext {
public fun <init> (Lio/sentry/PropagationContext;)V
public fun <init> (Lio/sentry/protocol/SentryId;Lio/sentry/SpanId;Lio/sentry/SpanId;Lio/sentry/Baggage;Ljava/lang/Boolean;)V
public static fun fromExistingTrace (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/ILogger;Ljava/lang/String;Ljava/lang/String;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/ILogger;Ljava/lang/String;Ljava/util/List;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/SentryTraceHeader;Lio/sentry/Baggage;Lio/sentry/SpanId;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/ILogger;Ljava/lang/String;Ljava/lang/String;Lio/sentry/SentryOptions;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/ILogger;Ljava/lang/String;Ljava/util/List;Lio/sentry/SentryOptions;)Lio/sentry/PropagationContext;
public static fun fromHeaders (Lio/sentry/SentryTraceHeader;Lio/sentry/Baggage;Lio/sentry/SpanId;Lio/sentry/SentryOptions;)Lio/sentry/PropagationContext;
public fun getBaggage ()Lio/sentry/Baggage;
public fun getParentSpanId ()Lio/sentry/SpanId;
public fun getSampleRand ()Ljava/lang/Double;
Expand Down Expand Up @@ -3573,6 +3580,7 @@ public class io/sentry/SentryOptions {
public fun getDistribution ()Lio/sentry/SentryOptions$DistributionOptions;
public fun getDistributionController ()Lio/sentry/IDistributionApi;
public fun getDsn ()Ljava/lang/String;
public fun getEffectiveOrgId ()Ljava/lang/String;
public fun getEnvelopeDiskCache ()Lio/sentry/cache/IEnvelopeCache;
public fun getEnvelopeReader ()Lio/sentry/IEnvelopeReader;
public fun getEnvironment ()Ljava/lang/String;
Expand Down Expand Up @@ -3613,6 +3621,7 @@ public class io/sentry/SentryOptions {
public fun getOnOversizedEvent ()Lio/sentry/SentryOptions$OnOversizedEventCallback;
public fun getOpenTelemetryMode ()Lio/sentry/SentryOpenTelemetryMode;
public fun getOptionsObservers ()Ljava/util/List;
public fun getOrgId ()Ljava/lang/String;
public fun getOutboxPath ()Ljava/lang/String;
public fun getPerformanceCollectors ()Ljava/util/List;
public fun getProfileLifecycle ()Lio/sentry/ProfileLifecycle;
Expand Down Expand Up @@ -3683,6 +3692,7 @@ public class io/sentry/SentryOptions {
public fun isSendDefaultPii ()Z
public fun isSendModules ()Z
public fun isStartProfilerOnAppStart ()Z
public fun isStrictTraceContinuation ()Z
public fun isTraceOptionsRequests ()Z
public fun isTraceSampling ()Z
public fun isTracingEnabled ()Z
Expand Down Expand Up @@ -3766,6 +3776,7 @@ public class io/sentry/SentryOptions {
public fun setOnDiscard (Lio/sentry/SentryOptions$OnDiscardCallback;)V
public fun setOnOversizedEvent (Lio/sentry/SentryOptions$OnOversizedEventCallback;)V
public fun setOpenTelemetryMode (Lio/sentry/SentryOpenTelemetryMode;)V
public fun setOrgId (Ljava/lang/String;)V
public fun setPrintUncaughtStackTrace (Z)V
public fun setProfileLifecycle (Lio/sentry/ProfileLifecycle;)V
public fun setProfileSessionSampleRate (Ljava/lang/Double;)V
Expand Down Expand Up @@ -3797,6 +3808,7 @@ public class io/sentry/SentryOptions {
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
public fun setSslSocketFactory (Ljavax/net/ssl/SSLSocketFactory;)V
public fun setStartProfilerOnAppStart (Z)V
public fun setStrictTraceContinuation (Z)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setThreadChecker (Lio/sentry/util/thread/IThreadChecker;)V
public fun setTraceOptionsRequests (Z)V
Expand Down
17 changes: 16 additions & 1 deletion sentry/src/main/java/io/sentry/Baggage.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public static Baggage fromEvent(
baggage.setPublicKey(options.retrieveParsedDsn().getPublicKey());
baggage.setRelease(event.getRelease());
baggage.setEnvironment(event.getEnvironment());
baggage.setOrgId(options.getEffectiveOrgId());
baggage.setTransaction(transaction);
// we don't persist sample rate
baggage.setSampleRate(null);
Expand Down Expand Up @@ -450,6 +451,16 @@ public void setReplayId(final @Nullable String replayId) {
set(DSCKeys.REPLAY_ID, replayId);
}

@ApiStatus.Internal
public @Nullable String getOrgId() {
return get(DSCKeys.ORG_ID);
}

@ApiStatus.Internal
public void setOrgId(final @Nullable String orgId) {
set(DSCKeys.ORG_ID, orgId);
}

/**
* Sets / updates a value, but only if the baggage is still mutable.
*
Expand Down Expand Up @@ -501,6 +512,7 @@ public void setValuesFromTransaction(
if (replayId != null && !SentryId.EMPTY_ID.equals(replayId)) {
setReplayId(replayId.toString());
}
setOrgId(sentryOptions.getEffectiveOrgId());
setSampleRate(sampleRate(samplingDecision));
setSampled(StringUtils.toString(sampled(samplingDecision)));
setSampleRand(sampleRand(samplingDecision));
Expand Down Expand Up @@ -536,6 +548,7 @@ public void setValuesFromScope(
if (!SentryId.EMPTY_ID.equals(replayId)) {
setReplayId(replayId.toString());
}
setOrgId(options.getEffectiveOrgId());
setTransaction(null);
setSampleRate(null);
setSampled(null);
Expand Down Expand Up @@ -632,6 +645,7 @@ public static final class DSCKeys {
public static final String SAMPLE_RAND = "sentry-sample_rand";
public static final String SAMPLED = "sentry-sampled";
public static final String REPLAY_ID = "sentry-replay_id";
public static final String ORG_ID = "sentry-org_id";

public static final List<String> ALL =
Arrays.asList(
Expand All @@ -644,6 +658,7 @@ public static final class DSCKeys {
SAMPLE_RATE,
SAMPLE_RAND,
SAMPLED,
REPLAY_ID);
REPLAY_ID,
ORG_ID);
}
}
21 changes: 21 additions & 0 deletions sentry/src/main/java/io/sentry/Dsn.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import io.sentry.util.Objects;
import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

final class Dsn {
private static final @NotNull Pattern ORG_ID_PATTERN = Pattern.compile("^o(\\d+)\\.");

private final @NotNull String projectId;
private final @Nullable String path;
private final @Nullable String secretKey;
private final @NotNull String publicKey;
private final @NotNull URI sentryUri;
private final @Nullable String orgId;

/*
/ The project ID which the authenticated user is bound to.
Expand Down Expand Up @@ -87,8 +92,24 @@ URI getSentryUri() {
sentryUri =
new URI(
scheme, null, uri.getHost(), uri.getPort(), path + "api/" + projectId, null, null);

// Extract org ID from host (e.g., "o123.ingest.sentry.io" -> "123")
String extractedOrgId = null;
final String host = uri.getHost();
if (host != null) {
final Matcher matcher = ORG_ID_PATTERN.matcher(host);
if (matcher.find()) {
extractedOrgId = matcher.group(1);
}
}
orgId = extractedOrgId;
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
}

public @Nullable String getOrgId() {
return orgId;
}

}
Loading
Loading