Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Breaking Changes

- Remove the deprecated `traceSampling` option (`SentryOptions.setTraceSampling`/`isTraceSampling` and the `io.sentry.traces.trace-sampling` manifest key); use `tracePropagationTargets` to control which outgoing requests get tracing headers ([#6415](https://github.com/getsentry/sentry-java/pull/6415))
- Remove the deprecated user feedback APIs ([#6337](https://github.com/getsentry/sentry-java/pull/6337))
- `UserFeedback` and `Sentry.captureUserFeedback(...)`: use `Sentry.feedback().capture(...)` with `io.sentry.protocol.Feedback` instead
- `Sentry.captureFeedback(...)`: use `Sentry.feedback().capture(...)` instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -101,7 +100,6 @@ final class ManifestMetadataReader {

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

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

static final String ATTACH_THREADS = "io.sentry.attach-threads";
Expand Down Expand Up @@ -474,9 +472,6 @@ static void applyMetadata(
}
}

options.setTraceSampling(
readBool(metadata, logger, TRACE_SAMPLING, options.isTraceSampling()));

options.setEnableAutoActivityLifecycleTracing(
readBool(
metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,31 +1034,6 @@ class ManifestMetadataReaderTest {
assertTrue(fixture.options.isEnableActivityLifecycleTracingAutoFinish)
}

@Test
fun `applyMetadata reads traceSampling to options`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.TRACE_SAMPLING to false)
val context = fixture.getContext(metaData = bundle)

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

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

@Test
fun `applyMetadata reads traceSampling to options and keeps default`() {
// Arrange
val context = fixture.getContext()

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

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

@Test
fun `applyMetadata reads profilesSampleRate from metadata`() {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SentryApolloInterceptor(
private fun addTracingHeaders(request: InterceptorRequest, span: ISpan?): RequestHeaders {
val requestHeaderBuilder = request.requestHeaders.toBuilder()

if (scopes.options.isTraceSampling && !isIgnored()) {
if (!isIgnored()) {
// we have no access to URI, no way to verify tracing origins
TracingUtils.trace(
scopes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class SentryFeignClientTest {

@Test
fun `when there is an active span, adds sentry trace header to the request`() {
fixture.sentryOptions.isTraceSampling = true
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
val sut = fixture.getSut()
sut.getOk()
Expand All @@ -107,7 +106,6 @@ class SentryFeignClientTest {

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

Expand Down Expand Up @@ -176,7 +174,6 @@ class SentryFeignClientTest {
@Test
fun `when request url not in tracing origins, does not add sentry trace header to the request`() {
fixture.sentryOptions.setTracePropagationTargets(listOf("http://some-other-url.sentry.io"))
fixture.sentryOptions.isTraceSampling = true
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
val sut = fixture.getSut()
sut.getOk()
Expand Down Expand Up @@ -420,7 +417,6 @@ class SentryFeignClientTest {

@Test
fun `adds W3C traceparent header when propagateTraceparent is enabled`() {
fixture.sentryOptions.isTraceSampling = true
fixture.sentryOptions.isPropagateTraceparent = true
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
val sut = fixture.getSut()
Expand All @@ -433,7 +429,6 @@ class SentryFeignClientTest {

@Test
fun `does not add W3C traceparent header when propagateTraceparent is disabled`() {
fixture.sentryOptions.isTraceSampling = true
fixture.sentryOptions.isPropagateTraceparent = false
fixture.sentryOptions.dsn = "https://key@sentry.io/proj"
val sut = fixture.getSut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ public OtelSpanWrapper(

@Override
public @Nullable TraceContext traceContext() {
if (scopes.getOptions().isTraceSampling()) {
final @Nullable Baggage baggage = context.getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return baggage.toTraceContext();
}
final @Nullable Baggage baggage = context.getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return baggage.toTraceContext();
}
return null;
}
Expand All @@ -249,12 +247,10 @@ private void updateBaggageValues(final @NotNull Baggage baggage) {

@Override
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
if (scopes.getOptions().isTraceSampling()) {
final @Nullable Baggage baggage = context.getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
}
final @Nullable Baggage baggage = context.getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,43 +261,6 @@ class OtelSentryPropagatorTest {
assertNull(carrier["baggage"])
}

@Test
fun `does not inject headers if URL in span attributes with tracePropagationTargets set to same url but trace sampling disabled`() {
Sentry.init { options ->
options.dsn = "https://key@sentry.io/proj"
options.setTracePropagationTargets(listOf("sentry.io"))
options.isTraceSampling = false
}
val propagator = OtelSentryPropagator()
val carrier = mutableMapOf<String, String>()

val otelAttributes = Attributes.of(UrlAttributes.URL_FULL, "https://sentry.io/some/path")
val sentrySpan = mock<IOtelSpanWrapper>()
whenever(sentrySpan.toSentryTrace())
.thenReturn(SentryTraceHeader("f9118105af4a2d42b4124532cd1065ff-424cffc8f94feeee-1"))
whenever(sentrySpan.toBaggageHeader(anyOrNull()))
.thenReturn(
BaggageHeader(
"sentry-environment=production,sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=df71f5972f754b4c85af13ff5c07017d"
)
)
whenever(sentrySpan.openTelemetrySpanAttributes).thenReturn(otelAttributes)
val otelSpanContext =
SpanContext.create(
"f9118105af4a2d42b4124532cd1065ff",
"424cffc8f94feeee",
TraceFlags.getSampled(),
TraceState.getDefault(),
)
val otelSpan = Span.wrap(otelSpanContext)
spanStorage.storeSentrySpan(otelSpanContext, sentrySpan)

propagator.inject(Context.root().with(otelSpan), carrier, MapSetter())

assertNull(carrier["sentry-trace"])
assertNull(carrier["baggage"])
}

@Test
fun `does not inject headers if sentry span missing`() {
val propagator = OtelSentryPropagator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class SentrySpanRestClientCustomizerTest {
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class SentrySpanRestTemplateCustomizerTest {
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class SentrySpanRestClientCustomizerTest {
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class SentrySpanRestTemplateCustomizerTest {
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class SentrySpanRestTemplateCustomizerTest {
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse().setBody("OK").setSocketPolicy(socketPolicy).setResponseCode(status.value())
Expand Down
2 changes: 0 additions & 2 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,6 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
public fun isStartProfilerOnAppStart ()Z
public fun isStrictTraceContinuation ()Z
public fun isTraceOptionsRequests ()Z
public fun isTraceSampling ()Z
public fun isTracingEnabled ()Z
public fun merge (Lio/sentry/ExternalOptions;)V
public fun setAppStartExtender (Lio/sentry/IAppStartExtender;)V
Expand Down Expand Up @@ -3778,7 +3777,6 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
public fun setTimerExecutorService (Lio/sentry/ISentryExecutorService;)V
public fun setTraceOptionsRequests (Z)V
public fun setTracePropagationTargets (Ljava/util/List;)V
public fun setTraceSampling (Z)V
public fun setTracesSampleRate (Ljava/lang/Double;)V
public fun setTracesSampler (Lio/sentry/SentryOptions$TracesSamplerCallback;)V
public fun setTransactionProfiler (Lio/sentry/ITransactionProfiler;)V
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/ISpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ default ISpan startChild(
/**
* Returns the trace context.
*
* @return a trace context or {@code null} if {@link SentryOptions#isTraceSampling()} is disabled.
* @return a trace context or {@code null} if there is no baggage.
*/
@Nullable
@ApiStatus.Experimental
Expand All @@ -100,7 +100,7 @@ default ISpan startChild(
/**
* Returns the baggage that can be sent as "baggage" header.
*
* @return BaggageHeader or {@code null} if {@link SentryOptions#isTraceSampling()} is disabled.
* @return BaggageHeader or {@code null} if there is no baggage.
*/
@Nullable
@ApiStatus.Experimental
Expand Down
33 changes: 0 additions & 33 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,6 @@ public class SentryOptions implements RateLimiterConfig {
*/
private @NotNull RequestSize maxRequestBodySize = RequestSize.NONE;

/**
* Controls if the `baggage` header is attached to HTTP client integrations and if the `trace`
* header is attached to envelopes.
*/
private boolean traceSampling = true;

/**
* Configures the profiles sample rate as a percentage of sampled transactions to be sent in the
* range of 0.0 to 1.0. if 1.0 is set it means that 100% of sampled transactions will send a
Expand Down Expand Up @@ -2142,33 +2136,6 @@ public void setMaxRequestBodySize(final @NotNull RequestSize maxRequestBodySize)
this.maxRequestBodySize = maxRequestBodySize;
}

/**
* Returns whether the `baggage` header is attached to HTTP client integrations and the `trace`
* header is attached to envelopes.
*
* <p>Note: this is an experimental API and will be removed without notice.
*
* @return true if enabled
*/
@ApiStatus.Experimental
public boolean isTraceSampling() {
return traceSampling;
}

/**
* Controls if the `baggage` header is attached HTTP client integrations and if the `trace` header
* is attached to envelopes. Defaults to false.
*
* <p>Note: this is an experimental API and will be removed without notice.
*
* @deprecated please use {{@link SentryOptions#setTracePropagationTargets(List)}} instead
* @param traceSampling - if trace sampling should be enabled
*/
@Deprecated
public void setTraceSampling(boolean traceSampling) {
this.traceSampling = traceSampling;
}

/**
* Returns the maximum trace file size for each envelope item in bytes.
*
Expand Down
20 changes: 8 additions & 12 deletions sentry/src/main/java/io/sentry/SentryTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,10 @@ public void finish(@Nullable SpanStatus status, @Nullable SentryDate finishDate)

@Override
public @Nullable TraceContext traceContext() {
if (scopes.getOptions().isTraceSampling()) {
final @Nullable Baggage baggage = getSpanContext().getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return baggage.toTraceContext();
}
final @Nullable Baggage baggage = getSpanContext().getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return baggage.toTraceContext();
}
return null;
}
Expand All @@ -752,12 +750,10 @@ private void updateBaggageValues(final @NotNull Baggage baggage) {

@Override
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
if (scopes.getOptions().isTraceSampling()) {
final @Nullable Baggage baggage = getSpanContext().getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
}
final @Nullable Baggage baggage = getSpanContext().getBaggage();
if (baggage != null) {
updateBaggageValues(baggage);
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/util/TracingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void setTrace(
@Nullable List<String> thirdPartyBaggageHeaders,
final @Nullable ISpan span) {
final @NotNull SentryOptions sentryOptions = scopes.getOptions();
if (sentryOptions.isTraceSampling() && shouldAttachTracingHeaders(requestUrl, sentryOptions)) {
if (shouldAttachTracingHeaders(requestUrl, sentryOptions)) {
return trace(scopes, thirdPartyBaggageHeaders, span);
}

Expand Down
1 change: 1 addition & 0 deletions sentry/src/test/java/io/sentry/OutboxSenderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OutboxSenderTest {

init {
whenever(options.dsn).thenReturn("https://key@sentry.io/proj")
whenever(options.retrieveParsedDsn()).thenReturn(Dsn("https://key@sentry.io/proj"))
whenever(options.dateProvider).thenReturn(SentryNanotimeDateProvider())
whenever(options.threadChecker).thenReturn(NoOpThreadChecker.getInstance())
whenever(options.continuousProfiler).thenReturn(NoOpContinuousProfiler.getInstance())
Expand Down
1 change: 0 additions & 1 deletion sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class SentryClientTest {
logs.setLoggerBatchProcessorFactory(loggerBatchProcessorFactory)
metrics.setMetricsBatchProcessorFactory(metricsBatchProcessorFactory)
release = "0.0.1"
isTraceSampling = true
}

init {
Expand Down
Loading
Loading