(callback: () => T)
| 272 | |
| 273 | /** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */ |
| 274 | export function suppressTracing<T>(callback: () => T): T { |
| 275 | const acs = getAcs(); |
| 276 | |
| 277 | if (acs.suppressTracing) { |
| 278 | return acs.suppressTracing(callback); |
| 279 | } |
| 280 | |
| 281 | return withScope(scope => { |
| 282 | // Note: We do not wait for the callback to finish before we reset the metadata |
| 283 | // the reason for this is that otherwise, in the browser this can lead to very weird behavior |
| 284 | // as there is only a single top scope, if the callback takes longer to finish, |
| 285 | // other, unrelated spans may also be suppressed, which we do not want |
| 286 | // so instead, we only suppress tracing synchronoysly in the browser |
| 287 | scope.setSDKProcessingMetadata({ [SUPPRESS_TRACING_KEY]: true }); |
| 288 | const res = callback(); |
| 289 | scope.setSDKProcessingMetadata({ [SUPPRESS_TRACING_KEY]: undefined }); |
| 290 | return res; |
| 291 | }); |
| 292 | } |
| 293 | |
| 294 | /** Check if tracing is suppressed. */ |
| 295 | export function isTracingSuppressed(scope = getCurrentScope()): boolean { |
no test coverage detected