Skip to content

Capture message respects ignoreUrls/whitelistUrls #774 #1080

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 10 commits into from
Oct 10, 2017
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
9 changes: 0 additions & 9 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ Those configuration options are documented below:
tags. Not setting this value is equivalent to a catch-all and will not
filter out any values.

Does not affect ``captureMessage`` or when non-error object is passed in
as argument to captureException.

.. code-block:: javascript

{
Expand All @@ -107,9 +104,6 @@ Those configuration options are documented below:
messages to be filtered out before being sent to Sentry as either
regular expressions or strings.

Does not affect captureMessage or when non-error object is passed in
as argument to captureException.

.. code-block:: javascript

{
Expand All @@ -128,9 +122,6 @@ Those configuration options are documented below:
ignoreUrls: [/graph\.facebook\.com/, 'http://example.com/script2.js']
}

Does not affect captureMessage or when non-error object is passed in
as argument to ``captureException``.

.. describe:: includePaths

An array of regex patterns to indicate which urls are a part of your
Expand Down
54 changes: 38 additions & 16 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,41 @@ Raven.prototype = {
options
);

if (this._globalOptions.stacktrace || (options && options.stacktrace)) {
var ex;
// Generate a "synthetic" stack trace from this point.
// NOTE: If you are a Sentry user, and you are seeing this stack frame, it is NOT indicative
// of a bug with Raven.js. Sentry generates synthetic traces either by configuration,
// or if it catches a thrown object without a "stack" property.
try {
throw new Error(msg);
} catch (ex1) {
ex = ex1;
}
var ex;
// Generate a "synthetic" stack trace from this point.
// NOTE: If you are a Sentry user, and you are seeing this stack frame, it is NOT indicative
// of a bug with Raven.js. Sentry generates synthetic traces either by configuration,
// or if it catches a thrown object without a "stack" property.
try {
throw new Error(msg);
} catch (ex1) {
ex = ex1;
}

// null exception name so `Error` isn't prefixed to msg
ex.name = null;
var stack = TraceKit.computeStackTrace(ex);

// stack[0] is `throw new Error(msg)` call itself, we are interested in the frame that was just before that, stack[1]
var initialCall = stack.stack[1];

// null exception name so `Error` isn't prefixed to msg
ex.name = null;
var fileurl = initialCall.url || '';

if (
!!this._globalOptions.ignoreUrls.test &&
this._globalOptions.ignoreUrls.test(fileurl)
) {
return;
}

if (
!!this._globalOptions.whitelistUrls.test &&
!this._globalOptions.whitelistUrls.test(fileurl)
) {
return;
}

if (this._globalOptions.stacktrace || (options && options.stacktrace)) {
options = objectMerge(
{
// fingerprint on msg, not stack trace (legacy behavior, could be
Expand All @@ -463,7 +483,6 @@ Raven.prototype = {
options
);

var stack = TraceKit.computeStackTrace(ex);
var frames = this._prepareFrames(stack, options);
data.stacktrace = {
// Sentry expects frames oldest to newest
Expand Down Expand Up @@ -1451,13 +1470,16 @@ Raven.prototype = {
if (
!!this._globalOptions.ignoreUrls.test &&
this._globalOptions.ignoreUrls.test(fileurl)
)
) {
return;
}

if (
!!this._globalOptions.whitelistUrls.test &&
!this._globalOptions.whitelistUrls.test(fileurl)
)
) {
return;
}

var data = objectMerge(
{
Expand Down
56 changes: 56 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,62 @@ describe('Raven (public API)', function() {
});
});

it('should respect `ignoreUrls`', function() {
this.sinon.stub(Raven, '_send');
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');

Raven._globalOptions.ignoreUrls = joinRegExp([/.+?host1.+/, /.+?host2.+/]);
TraceKitStub.returns({stack: [{url: 'http://host1/'}, {url: 'http://host1/'}]});
Raven.captureMessage('Do not capture');
assert.isFalse(Raven._send.called);
TraceKitStub.returns({stack: [{url: 'http://host2/'}, {url: 'http://host2/'}]});
Raven.captureMessage('Also do not capture');
assert.isFalse(Raven._send.called);
TraceKitStub.returns({stack: [{url: 'http://host3/'}, {url: 'http://host3/'}]});
Raven.captureMessage('Capture!');
assert.isTrue(Raven._send.calledOnce);
});

it('should handle empty `ignoreUrls`', function() {
this.sinon.stub(Raven, '_send');
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');

Raven._globalOptions.ignoreUrls = [];
TraceKitStub.returns({
stack: [{url: 'http://example.com'}, {url: 'http://example.com'}]
});
Raven.captureMessage('Capture!');
assert.isTrue(Raven._send.calledOnce);
});

it('should respect `whitelistUrls`', function() {
this.sinon.stub(Raven, '_send');
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');

Raven._globalOptions.whitelistUrls = joinRegExp([/.+?host1.+/, /.+?host2.+/]);
TraceKitStub.returns({stack: [{url: 'http://host1/'}, {url: 'http://host1/'}]});
Raven.captureMessage('Capture!');
assert.isTrue(Raven._send.calledOnce);
TraceKitStub.returns({stack: [{url: 'http://host2/'}, {url: 'http://host2/'}]});
Raven.captureMessage('Also capture!');
assert.isTrue(Raven._send.calledTwice);
TraceKitStub.returns({stack: [{url: 'http://host3/'}, {url: 'http://host3/'}]});
Raven.captureMessage('Do not capture!');
assert.isTrue(Raven._send.calledTwice);
});

it('should handle empty `whitelistUrls`', function() {
this.sinon.stub(Raven, '_send');
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');

Raven._globalOptions.whitelistUrls = [];
TraceKitStub.returns({
stack: [{url: 'http://example.com'}, {url: 'http://example.com'}]
});
Raven.captureMessage('Capture!');
assert.isTrue(Raven._send.calledOnce);
});

describe('synthetic traces', function() {
function assertSynthetic(frames) {
// Raven.captureMessage
Expand Down