Skip to content

Added whitelistUrls, inverse of ignoreUrls #110

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 2 commits into from
Jun 14, 2013
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
13 changes: 13 additions & 0 deletions docs/config/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ Similar to ``ignoreErrors``, but will ignore errors from whole urls patching a r
ignoreUrls: [/graph\.facebook\.com/i]
}

.. _config-whitelist-urls:

whitelistUrls
-------------

The inverse of ``ignoreUrls``. Only report errors from whole urls matching a regex pattern.

.. code-block:: javascript

{
whitelistUrls: [/getsentry\.com/, /cdn\.getsentry\.com/]
}

includePaths
------------

Expand Down
5 changes: 5 additions & 0 deletions docs/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ Contributing Back Code
~~~~~~~~~~~~~~~~~~~~~~

Please, send over suggestions and bug fixes in the form of pull requests on `GitHub <https://github.com/getsentry/raven-js>`_. Any fixes/features should include tests.

Documentation
-------------

The documentation is written using `reStructuredText <http://en.wikipedia.org/wiki/ReStructuredText>`_, and compiled using `Sphinx <http://sphinx-doc.org/>`_
2 changes: 2 additions & 0 deletions docs/tips/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Decluttering Sentry

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>`_.

See also: :ref:`Config: whitelistUrls<config-whitelist-urls>`

.. code-block:: javascript

var ravenOptions = {
Expand Down
3 changes: 3 additions & 0 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var _Raven = window.Raven,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
tags: {}
};
Expand Down Expand Up @@ -75,6 +76,7 @@ var Raven = {

// join regexp rules into one big rule
globalOptions.ignoreUrls = globalOptions.ignoreUrls.length ? joinRegExp(globalOptions.ignoreUrls) : false;
globalOptions.whitelistUrls = globalOptions.whitelistUrls.length ? joinRegExp(globalOptions.whitelistUrls) : false;
globalOptions.includePaths = joinRegExp(globalOptions.includePaths);

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

if (globalOptions.ignoreUrls && globalOptions.ignoreUrls.test(fileurl)) return;
if (globalOptions.whitelistUrls && !globalOptions.whitelistUrls.test(fileurl)) return;

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

Expand Down
42 changes: 42 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function flushRavenState() {
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
tags: {}
};
Expand Down Expand Up @@ -333,6 +334,18 @@ describe('globals', function() {
assert.isTrue(window.send.calledOnce);
});

it('should respect `whitelistUrls`', function() {
this.sinon.stub(window, 'send');

globalOptions.whitelistUrls = joinRegExp([/.+?host1.+/, /.+?host2.+/]);
processException('Error', 'error', 'http://host1/', []);
assert.equal(window.send.callCount, 1);
processException('Error', 'error', 'http://host2/', []);
assert.equal(window.send.callCount, 2);
processException('Error', 'error', 'http://host3/', []);
assert.equal(window.send.callCount, 2);
});

it('should send a proper payload with frames', function() {
this.sinon.stub(window, 'send');

Expand Down Expand Up @@ -771,6 +784,35 @@ describe('Raven (public API)', function() {
assert.deepEqual(globalOptions.ignoreErrors, ['Script error.'], 'it should install "Script error." by default');
assert.equal(globalProject, 2);
});

describe('whitelistUrls', function() {
it('should be false if none are passed', function() {
Raven.config('//[email protected]/2');
assert.equal(globalOptions.whitelistUrls, false);
});

it('should join into a single RegExp', function() {
Raven.config('//[email protected]/2', {
whitelistUrls: [
/my.app/i,
/other.app/i
]
});

assert.match(globalOptions.whitelistUrls, /my.app|other.app/i);
});

it('should handle strings as well', function() {
Raven.config('//[email protected]/2', {
whitelistUrls: [
/my.app/i,
"stringy.app"
]
});

assert.match(globalOptions.whitelistUrls, /my.app|stringy.app/i);
});
});
});

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