Skip to content

Commit bdab4bb

Browse files
committed
sample next spans after we have non-next instrumentation
1 parent a8531b5 commit bdab4bb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/opentelemetry/src/sampler.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ export class SentrySampler implements Sampler {
5252
return { decision: SamplingDecision.NOT_RECORD, traceState };
5353
}
5454

55-
// If we encounter a span emitted by Next.js, we do not want to sample it
56-
// The reason for this is that the data quality of the spans varies, it is different per version of Next,
57-
// and we need to keep our manual instrumentation around for the edge runtime anyhow.
58-
if (spanAttributes['next.span_type']) {
59-
return { decision: SamplingDecision.NOT_RECORD, traceState: traceState };
60-
}
61-
6255
// If we have a http.client span that has no local parent, we never want to sample it
6356
// but we want to leave downstream sampling decisions up to the server
6457
if (
@@ -71,6 +64,14 @@ export class SentrySampler implements Sampler {
7164

7265
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
7366

67+
// If we encounter a span emitted by Next.js, we do not want to sample it
68+
// The reason for this is that the data quality of the spans varies, it is different per version of Next,
69+
// and we need to keep our manual instrumentation around for the edge runtime anyhow.
70+
// BUT we only do this if we don't have a parent span with a sampling decision yet
71+
if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') {
72+
return { decision: SamplingDecision.NOT_RECORD, traceState: traceState };
73+
}
74+
7475
const [sampled, sampleRate] = sampleSpan(options, {
7576
name: spanName,
7677
attributes: spanAttributes,

0 commit comments

Comments
 (0)