Skip to content

Commit f6c11ea

Browse files
committed
Added whitelistUrls, inverse of ignoreUrls
1 parent cfb3e61 commit f6c11ea

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

docs/config/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ Similar to ``ignoreErrors``, but will ignore errors from whole urls patching a r
5555
ignoreUrls: [/graph\.facebook\.com/i]
5656
}
5757
58+
.. _config-whitelist-urls:
59+
60+
whitelistUrls
61+
-------------
62+
63+
The inverse of ``ignoreUrls``. Only report errors from whole urls matching a regex pattern.
64+
65+
.. code-block:: javascript
66+
67+
{
68+
whitelistUrls: [/getsentry\.com/, /cdn\.getsentry\.com/]
69+
}
70+
5871
includePaths
5972
------------
6073

docs/tips/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Decluttering Sentry
66

77
The community has compiled a list of common ignore rules for common things, like Facebook, Chrome extensions, etc. So it's recommended to at least check these out and see if they apply to you. `Check out the original gist <https://gist.github.com/impressiver/5092952>`_.
88

9+
See also: :ref:`Config: whitelistUrls<config-whitelist-urls>`
10+
911
.. code-block:: javascript
1012
1113
var ravenOptions = {

src/raven.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var _Raven = window.Raven,
1313
logger: 'javascript',
1414
ignoreErrors: [],
1515
ignoreUrls: [],
16+
whitelistUrls: [],
1617
includePaths: [],
1718
tags: {}
1819
};
@@ -75,6 +76,7 @@ var Raven = {
7576

7677
// join regexp rules into one big rule
7778
globalOptions.ignoreUrls = globalOptions.ignoreUrls.length ? joinRegExp(globalOptions.ignoreUrls) : false;
79+
globalOptions.whitelistUrls = globalOptions.whitelistUrls.length ? joinRegExp(globalOptions.whitelistUrls) : false;
7880
globalOptions.includePaths = joinRegExp(globalOptions.includePaths);
7981

8082
// "Script error." is hard coded into browsers for errors that it can't read.
@@ -436,6 +438,7 @@ function processException(type, message, fileurl, lineno, frames, options) {
436438
}
437439

438440
if (globalOptions.ignoreUrls && globalOptions.ignoreUrls.test(fileurl)) return;
441+
if (globalOptions.whitelistUrls && !globalOptions.whitelistUrls.test(fileurl)) return;
439442

440443
label = lineno ? message + ' at ' + lineno : message;
441444

test/raven.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function flushRavenState() {
88
logger: 'javascript',
99
ignoreErrors: [],
1010
ignoreUrls: [],
11+
whitelistUrls: [],
1112
includePaths: [],
1213
tags: {}
1314
};
@@ -333,6 +334,18 @@ describe('globals', function() {
333334
assert.isTrue(window.send.calledOnce);
334335
});
335336

337+
it('should respect `whitelistUrls`', function() {
338+
this.sinon.stub(window, 'send');
339+
340+
globalOptions.whitelistUrls = joinRegExp([/.+?host1.+/, /.+?host2.+/]);
341+
processException('Error', 'error', 'http://host1/', []);
342+
assert.equal(window.send.callCount, 1);
343+
processException('Error', 'error', 'http://host2/', []);
344+
assert.equal(window.send.callCount, 2);
345+
processException('Error', 'error', 'http://host3/', []);
346+
assert.equal(window.send.callCount, 2);
347+
});
348+
336349
it('should send a proper payload with frames', function() {
337350
this.sinon.stub(window, 'send');
338351

@@ -771,6 +784,35 @@ describe('Raven (public API)', function() {
771784
assert.deepEqual(globalOptions.ignoreErrors, ['Script error.'], 'it should install "Script error." by default');
772785
assert.equal(globalProject, 2);
773786
});
787+
788+
describe('whitelistUrls', function() {
789+
it('should be false if none are passed', function() {
790+
Raven.config('//[email protected]/2');
791+
assert.equal(globalOptions.whitelistUrls, false);
792+
});
793+
794+
it('should join into a single RegExp', function() {
795+
Raven.config('//[email protected]/2', {
796+
whitelistUrls: [
797+
/my.app/i,
798+
/other.app/i
799+
]
800+
});
801+
802+
assert.match(globalOptions.whitelistUrls, /my.app|other.app/i);
803+
});
804+
805+
it('should handle strings as well', function() {
806+
Raven.config('//[email protected]/2', {
807+
whitelistUrls: [
808+
/my.app/i,
809+
"stringy.app"
810+
]
811+
});
812+
813+
assert.match(globalOptions.whitelistUrls, /my.app|stringy.app/i);
814+
});
815+
});
774816
});
775817

776818
describe('.install', function() {

0 commit comments

Comments
 (0)