Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POTEL 33 - Record dropped spans when sampling OpenTelemetry spans #3552

Merged
merged 8 commits into from
Jul 5, 2024
Merged
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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there always only one span here, or should we also count the children?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sampler is invoked per span, before it's even started, we don't know the number of children it'll eventually have at this point. I can add something to the TODO list to see if we can come up with a number after the fact, but I'm not sure there's a callback that'll allow us to do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a way to record for child spans as well. We now record a lost span when copying a parent sampling decision that is false.

}

return new SentrySamplingResult(sentryDecision);
}

Expand All @@ -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
Expand Down
Loading