Skip to content

Commit e4333e5

Browse files
author
Luca Forstner
authored
ref(core): Move log message about invalid sample rate (#15215)
1 parent 5731cac commit e4333e5

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

packages/core/src/tracing/sampling.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ export function sampleSpan(
4141
const parsedSampleRate = parseSampleRate(sampleRate);
4242

4343
if (parsedSampleRate === undefined) {
44-
DEBUG_BUILD && logger.warn('[Tracing] Discarding transaction because of invalid sample rate.');
44+
DEBUG_BUILD &&
45+
logger.warn(
46+
`[Tracing] Discarding root span because of invalid sample rate. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(
47+
sampleRate,
48+
)} of type ${JSON.stringify(typeof sampleRate)}.`,
49+
);
4550
return [false];
4651
}
4752

packages/core/src/utils/hasTracingEnabled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function hasTracingEnabled(
2020
const options = maybeOptions || client?.getOptions();
2121
return (
2222
!!options &&
23-
// Note: This check is `!= null`, meaning "nullish"
23+
// 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)
2424
(options.tracesSampleRate != null || !!options.tracesSampler)
2525
);
2626
}

packages/core/src/utils/parseSampleRate.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { DEBUG_BUILD } from '../debug-build';
2-
import { logger } from '../utils-hoist/logger';
3-
41
/**
52
* Parse a sample rate from a given value.
63
* This will either return a boolean or number sample rate, if the sample rate is valid (between 0 and 1).
@@ -15,12 +12,6 @@ export function parseSampleRate(sampleRate: unknown): number | undefined {
1512

1613
const rate = typeof sampleRate === 'string' ? parseFloat(sampleRate) : sampleRate;
1714
if (typeof rate !== 'number' || isNaN(rate) || rate < 0 || rate > 1) {
18-
DEBUG_BUILD &&
19-
logger.warn(
20-
`[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(
21-
sampleRate,
22-
)} of type ${JSON.stringify(typeof sampleRate)}.`,
23-
);
2415
return undefined;
2516
}
2617

0 commit comments

Comments
 (0)