Skip to content

Commit c7875b1

Browse files
committed
Add sampleRate config option
1 parent b21d351 commit c7875b1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/config.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ Those configuration options are documented below:
145145
includePaths: [/https?:\/\/getsentry\.com/, /https?:\/\/cdn\.getsentry\.com/]
146146
}
147147
148+
.. describe:: sampleRate
149+
150+
A sampling rate to apply to events. A value of 0.0 will send no events,
151+
and a value of 1.0 will send all events (default).
152+
153+
.. code-block:: javascript
154+
155+
{
156+
sampleRate: 0.5 // send 50% of events, drop the other half
157+
}
158+
148159
.. describe:: dataCallback
149160

150161
A function that allows mutation of the data payload right before being

src/raven.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function Raven() {
5252
collectWindowErrors: true,
5353
maxMessageLength: 0,
5454
stackTraceLimit: 50,
55-
autoBreadcrumbs: true
55+
autoBreadcrumbs: true,
56+
sampleRate: 1
5657
};
5758
this._ignoreOnError = 0;
5859
this._isRavenInstalled = false;
@@ -1489,7 +1490,10 @@ Raven.prototype = {
14891490
return;
14901491
}
14911492

1492-
this._sendProcessedPayload(data);
1493+
if (Math.random() < globalOptions.sampleRate) {
1494+
this._sendProcessedPayload(data);
1495+
}
1496+
14931497
},
14941498

14951499
_getUuid: function () {

0 commit comments

Comments
 (0)