8000 core: Introduce sampleRate option · lordnox/sentry-javascript@9cbfdcd · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 9cbfdcd

Browse files
committed
core: Introduce sampleRate option
1 parent ed61bf9 commit 9cbfdcd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/core/src/base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,15 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
277277
};
278278
}
279279

280+
const { shouldSend, beforeSend, afterSend, sampleRate } = this.getOptions();
281+
282+
if (typeof sampleRate === 'number' && sampleRate > Math.random()) {
283+
return {
284+
status: Status.Skipped,
285+
};
286+
}
287+
280288
const prepared = await this.prepareEvent(event, scope);
281-
const { shouldSend, beforeSend, afterSend } = this.getOptions();
282289
if (prepared === null || (shouldSend && !shouldSend(prepared))) {
283290
return {
284291
status: Status.Skipped,

packages/core/src/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export interface Options {
8181
/** Console logging verbosity for the SDK Client. */
8282
logLevel?: LogLevel;
8383

84+
/** A global sample rate to apply to all events (0 - 1). */
85+
sampleRate?: number;
86+
8487
/**
8588
* A callback invoked during event submission, allowing to cancel the process.
8689
* If unspecified, all events will be sent to Sentry.

0 commit comments

Comments
 (0)
0