-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathhasSpansEnabled.ts
44 lines (40 loc) · 1.89 KB
/
hasSpansEnabled.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { getClient } from '../currentScopes';
import type { Options } from '../types-hoist';
// Treeshakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean | undefined;
/**
* Determines if span recording is currently enabled.
*
* Spans are recorded when at least one of `tracesSampleRate` and `tracesSampler`
* is defined in the SDK config. This function does not make any assumption about
* sampling decisions, it only checks if the SDK is configured to record spans.
*
* Important: This function only determines if span recording is enabled. Trace
* continuation and propagation is separately controlled and not covered by this function.
* If this function returns `false`, traces can still be propagated (which is what
* we refer to by "Tracing without Performance")
* @see https://develop.sentry.dev/sdk/telemetry/traces/tracing-without-performance/
*
* @param maybeOptions An SDK options object to be passed to this function.
* If this option is not provided, the function will use the current client's options.
*/
export function hasSpansEnabled(
maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler'> | undefined,
): boolean {
if (typeof __SENTRY_TRACING__ === 'boolean' && !__SENTRY_TRACING__) {
return false;
}
const options = maybeOptions || getClient()?.getOptions();
return (
!!options &&
// Note: This check is `!= null`, meaning "nullish". `0` is not "nullish", `undefined` and `null` are. (This comment was brought to you by 15 minutes of questioning life)
(options.tracesSampleRate != null || !!options.tracesSampler)
);
}
/**
* @see JSDoc of `hasSpansEnabled`
* @deprecated Use `hasSpansEnabled` instead, which is a more accurately named version of this function.
* This function will be removed in the next major version of the SDK.
*/
// TODO(v10): Remove this export
export const hasTracingEnabled = hasSpansEnabled;