Skip to content

ref(core): Move log message about invalid sample rate #15215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/tracing/sampling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export function sampleSpan(
const parsedSampleRate = parseSampleRate(sampleRate);

if (parsedSampleRate === undefined) {
DEBUG_BUILD && logger.warn('[Tracing] Discarding transaction because of invalid sample rate.');
DEBUG_BUILD &&
logger.warn(
`[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(
sampleRate,
)} of type ${JSON.stringify(typeof sampleRate)}.`,
);
return [false];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/hasTracingEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function hasTracingEnabled(
const options = maybeOptions || client?.getOptions();
return (
!!options &&
// Note: This check is `!= null`, meaning "nullish"
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol <3

(options.tracesSampleRate != null || !!options.tracesSampler)
);
}
9 changes: 0 additions & 9 deletions packages/core/src/utils/parseSampleRate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { DEBUG_BUILD } from '../debug-build';
import { logger } from '../utils-hoist/logger';

/**
* Parse a sample rate from a given value.
* This will either return a boolean or number sample rate, if the sample rate is valid (between 0 and 1).
Expand All @@ -15,12 +12,6 @@ export function parseSampleRate(sampleRate: unknown): number | undefined {

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

Expand Down
Loading