@@ -52,6 +52,13 @@ export class SentrySampler implements Sampler {
52
52
return { decision : SamplingDecision . NOT_RECORD , traceState } ;
53
53
}
54
54
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
+
55
62
// If we have a http.client span that has no local parent, we never want to sample it
56
63
// but we want to leave downstream sampling decisions up to the server
57
64
if (
@@ -62,20 +69,7 @@ export class SentrySampler implements Sampler {
62
69
return { decision : SamplingDecision . NOT_RECORD , traceState } ;
63
70
}
64
71
65
- let parentSampled : boolean | undefined = undefined ;
66
-
67
- // Only inherit sample rate if `traceId` is the same
68
- // Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
69
- if ( parentSpan && parentContext && isSpanContextValid ( parentContext ) && parentContext . traceId === traceId ) {
70
- if ( parentContext . isRemote ) {
71
- parentSampled = getParentRemoteSampled ( parentSpan ) ;
72
- DEBUG_BUILD &&
73
- logger . log ( `[Tracing] Inheriting remote parent's sampled decision for ${ spanName } : ${ parentSampled } ` ) ;
74
- } else {
75
- parentSampled = getSamplingDecision ( parentContext ) ;
76
- DEBUG_BUILD && logger . log ( `[Tracing] Inheriting parent's sampled decision for ${ spanName } : ${ parentSampled } ` ) ;
77
- }
78
- }
72
+ const parentSampled = parentSpan ? getParentSampled ( parentSpan , traceId , spanName ) : undefined ;
79
73
80
74
const [ sampled , sampleRate ] = sampleSpan ( options , {
81
75
name : spanName ,
@@ -129,3 +123,24 @@ function getParentRemoteSampled(parentSpan: Span): boolean | undefined {
129
123
// Only inherit sampled if `traceId` is the same
130
124
return traceparentData && traceId === traceparentData . traceId ? traceparentData . sampled : undefined ;
131
125
}
126
+
127
+ function getParentSampled ( parentSpan : Span , traceId : string , spanName : string ) : boolean | undefined {
128
+ const parentContext = parentSpan . spanContext ( ) ;
129
+
130
+ // Only inherit sample rate if `traceId` is the same
131
+ // Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
132
+ if ( isSpanContextValid ( parentContext ) && parentContext . traceId === traceId ) {
133
+ if ( parentContext . isRemote ) {
134
+ const parentSampled = getParentRemoteSampled ( parentSpan ) ;
135
+ DEBUG_BUILD &&
136
+ logger . log ( `[Tracing] Inheriting remote parent's sampled decision for ${ spanName } : ${ parentSampled } ` ) ;
137
+ return parentSampled ;
138
+ }
139
+
140
+ const parentSampled = getSamplingDecision ( parentContext ) ;
141
+ DEBUG_BUILD && logger . log ( `[Tracing] Inheriting parent's sampled decision for ${ spanName } : ${ parentSampled } ` ) ;
142
+ return parentSampled ;
143
+ }
144
+
145
+ return undefined ;
146
+ }
0 commit comments