@@ -41,7 +41,7 @@ export class SentrySampler implements Sampler {
41
41
const parentContext = parentSpan ?. spanContext ( ) ;
42
42
43
43
if ( ! hasTracingEnabled ( options ) ) {
44
- return sentrySamplerNoDecision ( { context, spanAttributes } ) ;
44
+ return wrapSamplingDecision ( { decision : undefined , context, spanAttributes } ) ;
45
45
}
46
46
47
47
// If we have a http.client span that has no local parent, we never want to sample it
@@ -51,7 +51,7 @@ export class SentrySampler implements Sampler {
51
51
spanAttributes [ SEMATTRS_HTTP_METHOD ] &&
52
52
( ! parentSpan || parentContext ?. isRemote )
53
53
) {
54
- return sentrySamplerNoDecision ( { context, spanAttributes } ) ;
54
+ return wrapSamplingDecision ( { decision : undefined , context, spanAttributes } ) ;
55
55
}
56
56
57
57
const parentSampled = parentSpan ? getParentSampled ( parentSpan , traceId , spanName ) : undefined ;
@@ -68,7 +68,7 @@ export class SentrySampler implements Sampler {
68
68
mutableSamplingDecision ,
69
69
) ;
70
70
if ( ! mutableSamplingDecision . decision ) {
71
- return sentrySamplerNoDecision ( { context, spanAttributes } ) ;
71
+ return wrapSamplingDecision ( { decision : undefined , context, spanAttributes } ) ;
72
72
}
73
73
74
74
const [ sampled , sampleRate ] = sampleSpan ( options , {
@@ -90,19 +90,19 @@ export class SentrySampler implements Sampler {
90
90
DEBUG_BUILD && logger . log ( `[Tracing] Not sampling span because HTTP method is '${ method } ' for ${ spanName } ` ) ;
91
91
92
92
return {
93
- ...sentrySamplerNotSampled ( { context, spanAttributes } ) ,
93
+ ...wrapSamplingDecision ( { decision : SamplingDecision . NOT_RECORD , context, spanAttributes } ) ,
94
94
attributes,
95
95
} ;
96
96
}
97
97
98
98
if ( ! sampled ) {
99
99
return {
100
- ...sentrySamplerNotSampled ( { context, spanAttributes } ) ,
100
+ ...wrapSamplingDecision ( { decision : SamplingDecision . NOT_RECORD , context, spanAttributes } ) ,
101
101
attributes,
102
102
} ;
103
103
}
104
104
return {
105
- ...sentrySamplerSampled ( { context, spanAttributes } ) ,
105
+ ...wrapSamplingDecision ( { decision : SamplingDecision . RECORD_AND_SAMPLED , context, spanAttributes } ) ,
106
106
attributes,
107
107
} ;
108
108
}
@@ -143,40 +143,28 @@ function getParentSampled(parentSpan: Span, traceId: string, spanName: string):
143
143
}
144
144
145
145
/**
146
- * Returns a SamplingResult that indicates that a span was not sampled, but no definite decision was made yet.
147
- * This indicates to downstream SDKs that they may make their own decision.
146
+ * Wrap a sampling decision with data that Sentry needs to work properly with it.
147
+ * If you pass `decision: undefined`, it will be treated as `NOT_RECORDING`, but in contrast to passing `NOT_RECORDING`
148
+ * it will not propagate this decision to downstream Sentry SDKs.
148
149
*/
149
- export function sentrySamplerNoDecision ( {
150
+ export function wrapSamplingDecision ( {
151
+ decision,
150
152
context,
151
153
spanAttributes,
152
- } : { context : Context ; spanAttributes : SpanAttributes } ) : SamplingResult {
154
+ } : { decision : SamplingDecision | undefined ; context : Context ; spanAttributes : SpanAttributes } ) : SamplingResult {
153
155
const traceState = getBaseTraceState ( context , spanAttributes ) ;
154
156
155
- return { decision : SamplingDecision . NOT_RECORD , traceState } ;
156
- }
157
-
158
- /**
159
- * Returns a SamplingResult that indicates that a span was not sampled.
160
- */
161
- export function sentrySamplerNotSampled ( {
162
- context,
163
- spanAttributes,
164
- } : { context : Context ; spanAttributes : SpanAttributes } ) : SamplingResult {
165
- const traceState = getBaseTraceState ( context , spanAttributes ) . set ( SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING , '1' ) ;
166
-
167
- return { decision : SamplingDecision . NOT_RECORD , traceState } ;
168
- }
157
+ // If the decision is undefined, we treat it as NOT_RECORDING, but we don't propagate this decision to downstream SDKs
158
+ // Which is done by not setting `SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING` traceState
159
+ if ( decision == undefined ) {
160
+ return { decision : SamplingDecision . NOT_RECORD , traceState } ;
161
+ }
169
162
170
- /**
171
- * Returns a SamplingResult that indicates that a span was sampled.
172
- */
173
- export function sentrySamplerSampled ( {
174
- context,
175
- spanAttributes,
176
- } : { context : Context ; spanAttributes : SpanAttributes } ) : SamplingResult {
177
- const traceState = getBaseTraceState ( context , spanAttributes ) ;
163
+ if ( decision === SamplingDecision . NOT_RECORD ) {
164
+ return { decision, traceState : traceState . set ( SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING , '1' ) } ;
165
+ }
178
166
179
- return { decision : SamplingDecision . RECORD_AND_SAMPLED , traceState } ;
167
+ return { decision, traceState } ;
180
168
}
181
169
182
170
function getBaseTraceState ( context : Context , spanAttributes : SpanAttributes ) : TraceStateInterface {
0 commit comments