Skip to content
Closed
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
17 changes: 17 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ Capturing Messages

Raven.captureMessage('Broken!')

Passing options
-----------------------

The ``captureMessage`` and ``captureException`` both allow options to be passed for them

.. describe:: skipSampleRate

Skips sampling rate checking this message and always sends it. Default: ``false``

.. code-block:: javascript

Raven.captureMessage('Something happened', {
options: {
skipSampleRate: true
}
});

.. _raven-js-additional-context:

Passing Additional Data
Expand Down
5 changes: 4 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,9 @@ Raven.prototype = {

_send: function(data) {
var globalOptions = this._globalOptions;
var options = data.options || {};
// delete `options` from data to so it doesn't get send with the outbound payload
delete data.options;

var baseData = {
project: this._globalProject,
Expand Down Expand Up @@ -1708,7 +1711,7 @@ Raven.prototype = {
return;
}

if (typeof globalOptions.sampleRate === 'number') {
if (typeof globalOptions.sampleRate === 'number' && !options.skipSampleRate) {
if (Math.random() < globalOptions.sampleRate) {
this._sendProcessedPayload(data);
}
Expand Down
24 changes: 24 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,18 @@ describe('Raven (public API)', function() {
assert.isTrue(Raven._send.calledOnce);
});

it('should respect `skipSampleRate` option', function() {
this.sinon.stub(Raven, '_makeRequest');
setupRaven();
Raven._globalOptions.sampleRate = 0.0;
Raven.captureMessage('This message should be sent', {
options: {
skipSampleRate: true
}
});
assert.equal(Raven._makeRequest.callCount, 1);
});

it('should not throw an error if not configured', function() {
this.sinon.stub(Raven, 'isSetup').returns(false);
this.sinon.stub(Raven, '_send');
Expand Down Expand Up @@ -2750,6 +2762,18 @@ describe('Raven (public API)', function() {
Raven.captureException(new Error('err'));
});
});

it('should respect `skipSampleRate`', function() {
this.sinon.stub(Raven, '_makeRequest');
setupRaven();
Raven._globalOptions.sampleRate = 0.0;
Raven.captureException(new Error('This error should be sent'), {
options: {
skipSampleRate: true
}
});
assert.equal(Raven._makeRequest.callCount, 1);
});
});

describe('.captureBreadcrumb', function() {
Expand Down