1
- import type { Options , SamplingContext } from '../types-hoist' ;
1
+ import type { Options , RequestEventData , SamplingContext } from '../types-hoist' ;
2
2
3
+ import { getIsolationScope } from '../currentScopes' ;
3
4
import { DEBUG_BUILD } from '../debug-build' ;
4
5
import { logger } from '../utils-hoist/logger' ;
5
6
import { hasTracingEnabled } from '../utils/hasTracingEnabled' ;
@@ -20,13 +21,22 @@ export function sampleSpan(
20
21
return [ false ] ;
21
22
}
22
23
24
+ // Casting this from unknown, as the type of `sdkProcessingMetadata` is only changed in v9 and `normalizedRequest` is set in SentryHttpInstrumentation
25
+ const normalizedRequest = getIsolationScope ( ) . getScopeData ( ) . sdkProcessingMetadata
26
+ . normalizedRequest as RequestEventData ;
27
+
28
+ const enhancedSamplingContext = {
29
+ ...samplingContext ,
30
+ normalizedRequest : samplingContext . normalizedRequest || normalizedRequest ,
31
+ } ;
32
+
23
33
// we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` nor `enableTracing` were defined, so one of these should
24
34
// work; prefer the hook if so
25
35
let sampleRate ;
26
36
if ( typeof options . tracesSampler === 'function' ) {
27
- sampleRate = options . tracesSampler ( samplingContext ) ;
28
- } else if ( samplingContext . parentSampled !== undefined ) {
29
- sampleRate = samplingContext . parentSampled ;
37
+ sampleRate = options . tracesSampler ( enhancedSamplingContext ) ;
38
+ } else if ( enhancedSamplingContext . parentSampled !== undefined ) {
39
+ sampleRate = enhancedSamplingContext . parentSampled ;
30
40
} else if ( typeof options . tracesSampleRate !== 'undefined' ) {
31
41
sampleRate = options . tracesSampleRate ;
32
42
} else {
0 commit comments