diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c66d53b950..b427a01c9c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Traces were broken because on an incoming request, OtelSentrySpanProcessor did not set the parentSpanId on the span correctly. Traces were not referencing the actual parent span but some other (random) span ID which the server doesn't know. - Attach active span to scope when using OpenTelemetry ([#3549](https://github.com/getsentry/sentry-java/pull/3549)) - Errors weren't linked to traces correctly due to parts of the SDK not knowing the current span +- Record dropped spans in client report when sampling out OpenTelemetry spans ([#3552](https://github.com/getsentry/sentry-java/pull/3552)) ## 8.0.0-alpha.3 diff --git a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java index 6412badc262..eaed924bfa8 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java +++ b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java @@ -11,6 +11,7 @@ import io.opentelemetry.sdk.trace.samplers.SamplingDecision; import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.sentry.Baggage; +import io.sentry.DataCategory; import io.sentry.IScopes; import io.sentry.PropagationContext; import io.sentry.SamplingContext; @@ -19,6 +20,7 @@ import io.sentry.SpanId; import io.sentry.TracesSamplingDecision; import io.sentry.TransactionContext; +import io.sentry.clientreport.DiscardReason; import io.sentry.protocol.SentryId; import java.util.List; import org.jetbrains.annotations.NotNull; @@ -94,7 +96,18 @@ public SamplingResult shouldSample( .getOptions() .getInternalTracesSampler() .sample(new SamplingContext(transactionContext, null)); - // TODO [POTEL] if sampling decision = false, we should record it in client report + + if (!sentryDecision.getSampled()) { + scopes + .getOptions() + .getClientReportRecorder() + .recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.Transaction); + scopes + .getOptions() + .getClientReportRecorder() + .recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.Span); + } + return new SentrySamplingResult(sentryDecision); } @@ -103,6 +116,12 @@ public SamplingResult shouldSample( final @Nullable TracesSamplingDecision parentSamplingDecision = parentSentrySpan.getSamplingDecision(); if (parentSamplingDecision != null) { + if (!parentSamplingDecision.getSampled()) { + scopes + .getOptions() + .getClientReportRecorder() + .recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.Span); + } return new SentrySamplingResult(parentSamplingDecision); } else { // this should never happen and only serve to calm the compiler