Skip to content

Commit fb3e477

Browse files
sentry-junior[bot]adinauerclaude
authored
ref(core): Remove deprecated traceSampling option (#6415)
* ref(core): Remove deprecated traceSampling option Remove SentryOptions.isTraceSampling/setTraceSampling and the io.sentry.traces.trace-sampling Android manifest key. The option has defaulted to true since 6.5.0 and was marked experimental and deprecated in favor of tracePropagationTargets. Trace context and baggage are now always produced when a transaction has baggage, and outgoing tracing headers are controlled by tracePropagationTargets alone. Co-Authored-By: Alexander Dinauer <alexander.dinauer@sentry.io> * changelog Co-Authored-By: Alexander Dinauer <alexander.dinauer@sentry.io> * test(core): Stub parsed DSN in OutboxSenderTest The mocked SentryOptions used to return false for isTraceSampling, which skipped baggage computation on transaction finish. With the option removed, SentryTracer always fills baggage values and needs a parsed DSN. * docs: Clarify traceSampling migration Distinguish URL-aware propagation targets from Apollo v2 and document its attachTracingHeaders opt-out, which preserves span creation. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Alexander Dinauer <alexander.dinauer@sentry.io> Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent fe83822 commit fb3e477

22 files changed

Lines changed: 28 additions & 182 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- `SentryOptions.getIgnoredErrors()`, `getIgnoredTransactions()`, `getIgnoredCheckIns()` and `getIgnoredSpanOrigins()` now return `List<String>` instead of `List<FilterString>`, matching their setters ([#6489](https://github.com/getsentry/sentry-java/pull/6489))
1313
- The SDK is now compiled for Java 11 instead of Java 8. JVM applications need Java 11 or newer ([#6459](https://github.com/getsentry/sentry-java/pull/6459))
1414
- Default trace context status to `ok` when an active span has no explicit status ([#6418](https://github.com/getsentry/sentry-java/pull/6418))
15+
- Remove the deprecated `traceSampling` option (`SentryOptions.setTraceSampling`/`isTraceSampling` and the `io.sentry.traces.trace-sampling` manifest key) ([#6415](https://github.com/getsentry/sentry-java/pull/6415))
16+
- Use `tracePropagationTargets` to control which URL-aware outgoing requests get tracing headers.
17+
- For Apollo v2, pass `attachTracingHeaders = false` to `SentryApolloInterceptor` to disable the headers while still creating spans.
1518
- Remove the deprecated user feedback APIs ([#6337](https://github.com/getsentry/sentry-java/pull/6337))
1619
- `UserFeedback` and `Sentry.captureUserFeedback(...)`: use `Sentry.feedback().capture(...)` with `io.sentry.protocol.Feedback` instead
1720
- `Sentry.captureFeedback(...)`: use `Sentry.feedback().capture(...)` instead

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Locale;
2525
import java.util.Map;
2626
import java.util.Set;
27-
import org.jetbrains.annotations.ApiStatus;
2827
import org.jetbrains.annotations.NotNull;
2928
import org.jetbrains.annotations.Nullable;
3029

@@ -101,7 +100,6 @@ final class ManifestMetadataReader {
101100

102101
static final String PROFILER_START_ON_APP_START = "io.sentry.traces.profiling.start-on-app-start";
103102

104-
@ApiStatus.Experimental static final String TRACE_SAMPLING = "io.sentry.traces.trace-sampling";
105103
static final String TRACE_PROPAGATION_TARGETS = "io.sentry.traces.trace-propagation-targets";
106104

107105
static final String ATTACH_THREADS = "io.sentry.attach-threads";
@@ -475,9 +473,6 @@ static void applyMetadata(
475473
}
476474
}
477475

478-
options.setTraceSampling(
479-
readBool(metadata, logger, TRACE_SAMPLING, options.isTraceSampling()));
480-
481476
options.setEnableAutoActivityLifecycleTracing(
482477
readBool(
483478
metadata,

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,31 +1033,6 @@ class ManifestMetadataReaderTest {
10331033
assertTrue(fixture.options.isEnableActivityLifecycleTracingAutoFinish)
10341034
}
10351035

1036-
@Test
1037-
fun `applyMetadata reads traceSampling to options`() {
1038-
// Arrange
1039-
val bundle = bundleOf(ManifestMetadataReader.TRACE_SAMPLING to false)
1040-
val context = fixture.getContext(metaData = bundle)
1041-
1042-
// Act
1043-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1044-
1045-
// Assert
1046-
assertFalse(fixture.options.isTraceSampling)
1047-
}
1048-
1049-
@Test
1050-
fun `applyMetadata reads traceSampling to options and keeps default`() {
1051-
// Arrange
1052-
val context = fixture.getContext()
1053-
1054-
// Act
1055-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1056-
1057-
// Assert
1058-
assertTrue(fixture.options.isTraceSampling)
1059-
}
1060-
10611036
@Test
10621037
fun `applyMetadata reads profilesSampleRate from metadata`() {
10631038
// Arrange

‎sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class SentryApolloInterceptor(
144144
private fun addTracingHeaders(request: InterceptorRequest, span: ISpan?): RequestHeaders {
145145
val requestHeaderBuilder = request.requestHeaders.toBuilder()
146146

147-
if (attachTracingHeaders && scopes.options.isTraceSampling && !isIgnored()) {
147+
if (attachTracingHeaders && !isIgnored()) {
148148
// we have no access to URI, no way to verify tracing origins
149149
TracingUtils.trace(
150150
scopes,

‎sentry-openfeign/src/test/kotlin/io/sentry/openfeign/SentryFeignClientTest.kt‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class SentryFeignClientTest {
9999

100100
@Test
101101
fun `when there is an active span, adds sentry trace header to the request`() {
102-
fixture.sentryOptions.isTraceSampling = true
103102
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
104103
val sut = fixture.getSut()
105104
sut.getOk()
@@ -111,7 +110,6 @@ class SentryFeignClientTest {
111110

112111
@Test
113112
fun `when there is an active span, existing baggage headers are merged with sentry baggage into single header`() {
114-
fixture.sentryOptions.isTraceSampling = true
115113
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
116114
val sut = fixture.getSut()
117115

@@ -180,7 +178,6 @@ class SentryFeignClientTest {
180178
@Test
181179
fun `when request url not in tracing origins, does not add sentry trace header to the request`() {
182180
fixture.sentryOptions.setTracePropagationTargets(listOf("http://some-other-url.sentry.io"))
183-
fixture.sentryOptions.isTraceSampling = true
184181
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
185182
val sut = fixture.getSut()
186183
sut.getOk()
@@ -424,7 +421,6 @@ class SentryFeignClientTest {
424421

425422
@Test
426423
fun `adds W3C traceparent header when propagateTraceparent is enabled`() {
427-
fixture.sentryOptions.isTraceSampling = true
428424
fixture.sentryOptions.isPropagateTraceparent = true
429425
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
430426
val sut = fixture.getSut()
@@ -437,7 +433,6 @@ class SentryFeignClientTest {
437433

438434
@Test
439435
fun `does not add W3C traceparent header when propagateTraceparent is disabled`() {
440-
fixture.sentryOptions.isTraceSampling = true
441436
fixture.sentryOptions.isPropagateTraceparent = false
442437
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
443438
val sut = fixture.getSut()

‎sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OtelSpanWrapper.java‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,10 @@ public OtelSpanWrapper(
192192

193193
@Override
194194
public @Nullable TraceContext traceContext() {
195-
if (scopes.getOptions().isTraceSampling()) {
196-
final @Nullable Baggage baggage = context.getBaggage();
197-
if (baggage != null) {
198-
updateBaggageValues(baggage);
199-
return baggage.toTraceContext();
200-
}
195+
final @Nullable Baggage baggage = context.getBaggage();
196+
if (baggage != null) {
197+
updateBaggageValues(baggage);
198+
return baggage.toTraceContext();
201199
}
202200
return null;
203201
}
@@ -230,12 +228,10 @@ private void updateBaggageValues(final @NotNull Baggage baggage) {
230228

231229
@Override
232230
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
233-
if (scopes.getOptions().isTraceSampling()) {
234-
final @Nullable Baggage baggage = context.getBaggage();
235-
if (baggage != null) {
236-
updateBaggageValues(baggage);
237-
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
238-
}
231+
final @Nullable Baggage baggage = context.getBaggage();
232+
if (baggage != null) {
233+
updateBaggageValues(baggage);
234+
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
239235
}
240236
return null;
241237
}

‎sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/OtelSentryPropagatorTest.kt‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -261,43 +261,6 @@ class OtelSentryPropagatorTest {
261261
assertNull(carrier["baggage"])
262262
}
263263

264-
@Test
265-
fun `does not inject headers if URL in span attributes with tracePropagationTargets set to same url but trace sampling disabled`() {
266-
Sentry.init { options ->
267-
options.dsn = "https://key@sentry.io/proj"
268-
options.setTracePropagationTargets(listOf("sentry.io"))
269-
options.isTraceSampling = false
270-
}
271-
val propagator = OtelSentryPropagator()
272-
val carrier = mutableMapOf<String, String>()
273-
274-
val otelAttributes = Attributes.of(UrlAttributes.URL_FULL, "https://sentry.io/some/path")
275-
val sentrySpan = mock<IOtelSpanWrapper>()
276-
whenever(sentrySpan.toSentryTrace())
277-
.thenReturn(SentryTraceHeader("f9118105af4a2d42b4124532cd1065ff-424cffc8f94feeee-1"))
278-
whenever(sentrySpan.toBaggageHeader(anyOrNull()))
279-
.thenReturn(
280-
BaggageHeader(
281-
"sentry-environment=production,sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=df71f5972f754b4c85af13ff5c07017d"
282-
)
283-
)
284-
whenever(sentrySpan.openTelemetrySpanAttributes).thenReturn(otelAttributes)
285-
val otelSpanContext =
286-
SpanContext.create(
287-
"f9118105af4a2d42b4124532cd1065ff",
288-
"424cffc8f94feeee",
289-
TraceFlags.getSampled(),
290-
TraceState.getDefault(),
291-
)
292-
val otelSpan = Span.wrap(otelSpanContext)
293-
spanStorage.storeSentrySpan(otelSpanContext, sentrySpan)
294-
295-
propagator.inject(Context.root().with(otelSpan), carrier, MapSetter())
296-
297-
assertNull(carrier["sentry-trace"])
298-
assertNull(carrier["baggage"])
299-
}
300-
301264
@Test
302265
fun `does not inject headers if sentry span missing`() {
303266
val propagator = OtelSentryPropagator()

‎sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentrySpanRestClientCustomizerTest.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class SentrySpanRestClientCustomizerTest {
7777
}
7878

7979
sentryOptions.dsn = "https://key@sentry.io/proj"
80-
sentryOptions.isTraceSampling = true
8180

8281
mockServer.enqueue(
8382
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())

‎sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentrySpanRestTemplateCustomizerTest.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class SentrySpanRestTemplateCustomizerTest {
8181
}
8282

8383
sentryOptions.dsn = "https://key@sentry.io/proj"
84-
sentryOptions.isTraceSampling = true
8584

8685
mockServer.enqueue(
8786
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())

‎sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentrySpanRestClientCustomizerTest.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class SentrySpanRestClientCustomizerTest {
7777
}
7878

7979
sentryOptions.dsn = "https://key@sentry.io/proj"
80-
sentryOptions.isTraceSampling = true
8180

8281
mockServer.enqueue(
8382
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())

0 commit comments

Comments
 (0)