@@ -3,6 +3,7 @@ import type { ClientOptions, Scope, SentrySpanArguments, Span, SpanTimeInput, St
3
3
import { propagationContextFromHeaders } from '@sentry/utils' ;
4
4
import type { AsyncContextStrategy } from '../asyncContext' ;
5
5
import { getMainCarrier } from '../asyncContext' ;
6
+ import { SUPPRESS_TRACING_KEY } from '../constants' ;
6
7
import { getClient , getCurrentScope , getIsolationScope , withScope } from '../currentScopes' ;
7
8
8
9
import { getAsyncContextStrategy } from '../hub' ;
@@ -204,6 +205,20 @@ export function withActiveSpan<T>(span: Span | null, callback: (scope: Scope) =>
204
205
} ) ;
205
206
}
206
207
208
+ /** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
209
+ export function suppressTracing < T > ( callback : ( ) => T ) : T {
210
+ const acs = getAcs ( ) ;
211
+
212
+ if ( acs . suppressTracing ) {
213
+ return acs . suppressTracing ( callback ) ;
214
+ }
215
+
216
+ return withScope ( scope => {
217
+ scope . setSDKProcessingMetadata ( { [ SUPPRESS_TRACING_KEY ] : true } ) ;
218
+ return callback ( ) ;
219
+ } ) ;
220
+ }
221
+
207
222
function createChildSpanOrTransaction ( {
208
223
parentSpan,
209
224
spanContext,
@@ -237,6 +252,7 @@ function createChildSpanOrTransaction({
237
252
parentSpanId,
238
253
...spanContext ,
239
254
} ,
255
+ scope ,
240
256
parentSampled ,
241
257
) ;
242
258
@@ -258,6 +274,7 @@ function createChildSpanOrTransaction({
258
274
parentSpanId,
259
275
...spanContext ,
260
276
} ,
277
+ scope ,
261
278
parentSampled ,
262
279
) ;
263
280
@@ -296,20 +313,22 @@ function getAcs(): AsyncContextStrategy {
296
313
return getAsyncContextStrategy ( carrier ) ;
297
314
}
298
315
299
- function _startRootSpan ( spanArguments : SentrySpanArguments , parentSampled ?: boolean ) : SentrySpan {
316
+ function _startRootSpan ( spanArguments : SentrySpanArguments , scope : Scope , parentSampled ?: boolean ) : SentrySpan {
300
317
const client = getClient ( ) ;
301
318
const options : Partial < ClientOptions > = ( client && client . getOptions ( ) ) || { } ;
302
319
303
320
const { name = '' , attributes } = spanArguments ;
304
- const [ sampled , sampleRate ] = sampleSpan ( options , {
305
- name,
306
- parentSampled,
307
- attributes,
308
- transactionContext : {
309
- name,
310
- parentSampled,
311
- } ,
312
- } ) ;
321
+ const [ sampled , sampleRate ] = scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ]
322
+ ? [ false ]
323
+ : sampleSpan ( options , {
324
+ name,
325
+ parentSampled,
326
+ attributes,
327
+ transactionContext : {
328
+ name,
329
+ parentSampled,
330
+ } ,
331
+ } ) ;
313
332
314
333
const transaction = new SentrySpan ( {
315
334
...spanArguments ,
0 commit comments