From bd6d462bccc907f84abca3ea6a21d4f4b8f2e618 Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sat, 7 Oct 2017 22:07:52 -0400 Subject: [PATCH 01/10] Always generate error in captureMessage --- src/raven.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/raven.js b/src/raven.js index 5f79ebcb0ac9..38982fe26046 100644 --- a/src/raven.js +++ b/src/raven.js @@ -435,21 +435,22 @@ 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; + // null exception name so `Error` isn't prefixed to msg + ex.name = null; + var stack = TraceKit.computeStackTrace(ex); + if (this._globalOptions.stacktrace || (options && options.stacktrace)) { options = objectMerge( { // fingerprint on msg, not stack trace (legacy behavior, could be @@ -463,7 +464,6 @@ Raven.prototype = { options ); - var stack = TraceKit.computeStackTrace(ex); var frames = this._prepareFrames(stack, options); data.stacktrace = { // Sentry expects frames oldest to newest From 15a9473df1fc281fe01cce00dde777ce5cea945e Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sun, 8 Oct 2017 09:44:22 -0400 Subject: [PATCH 02/10] Get previous call and file url from race --- src/raven.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/raven.js b/src/raven.js index 38982fe26046..1c524050ecab 100644 --- a/src/raven.js +++ b/src/raven.js @@ -450,6 +450,10 @@ Raven.prototype = { ex.name = null; var stack = TraceKit.computeStackTrace(ex); + var prvCall = stack.stack[1]; + + var fileurl = prvCall.url || ''; + if (this._globalOptions.stacktrace || (options && options.stacktrace)) { options = objectMerge( { From 17b230371e8af604ec6d82b0377a7ccb95823114 Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sun, 8 Oct 2017 09:45:25 -0400 Subject: [PATCH 03/10] Test file url against ignore/whitelist urls --- src/raven.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/raven.js b/src/raven.js index 1c524050ecab..41482eb7fd89 100644 --- a/src/raven.js +++ b/src/raven.js @@ -454,6 +454,17 @@ Raven.prototype = { var fileurl = prvCall.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( { From bf2792f6965f505bed8a69273dbb5d7cc10308ef Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sun, 8 Oct 2017 10:25:13 -0400 Subject: [PATCH 04/10] Tests for ignoreUrls --- test/raven.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/raven.test.js b/test/raven.test.js index 01d9ea29cf57..618beae4badc 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -2635,6 +2635,34 @@ 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); + }); + describe('synthetic traces', function() { function assertSynthetic(frames) { // Raven.captureMessage From 71c6ef7237dbf8d504c5e1642d409b78ff0af40c Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sun, 8 Oct 2017 10:26:47 -0400 Subject: [PATCH 05/10] Tests for whitelistUrls --- test/raven.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/raven.test.js b/test/raven.test.js index 618beae4badc..a8f138740731 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -2663,6 +2663,34 @@ describe('Raven (public API)', function() { 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.equal(Raven._send.callCount, 1); + TraceKitStub.returns({stack: [{url: 'http://host2/'}, {url: 'http://host2/'}]}); + Raven.captureMessage('Also capture!'); + assert.equal(Raven._send.callCount, 2); + TraceKitStub.returns({stack: [{url: 'http://host3/'}, {url: 'http://host3/'}]}); + Raven.captureMessage('Do not capture!'); + assert.equal(Raven._send.callCount, 2); + }); + + 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 From 84cc587171b926994e5d093d688f841c2507ee6a Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Sun, 8 Oct 2017 10:31:36 -0400 Subject: [PATCH 06/10] Update docs --- docs/config.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 65fed4b1e3a7..0f1027656538 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -90,7 +90,7 @@ 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 + Does not affect when non-error object is passed in as argument to captureException. .. code-block:: javascript @@ -107,7 +107,7 @@ 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 + Does not affect when non-error object is passed in as argument to captureException. .. code-block:: javascript @@ -128,7 +128,7 @@ 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 + Does not affect when non-error object is passed in as argument to ``captureException``. .. describe:: includePaths From 38b474e4a57c77b5215621cf678941b19352c15e Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Mon, 9 Oct 2017 11:26:16 -0400 Subject: [PATCH 07/10] Update docs --- docs/config.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 0f1027656538..e236cde86b98 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -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 when non-error object is passed in - as argument to captureException. - .. code-block:: javascript { @@ -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 when non-error object is passed in - as argument to captureException. - .. code-block:: javascript { @@ -128,9 +122,6 @@ Those configuration options are documented below: ignoreUrls: [/graph\.facebook\.com/, 'http://example.com/script2.js'] } - Does not affect 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 From c7506e2f81e81d07e56836ed2a667042c6d538c3 Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Mon, 9 Oct 2017 11:30:40 -0400 Subject: [PATCH 08/10] Update captureMessage --- src/raven.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/raven.js b/src/raven.js index 41482eb7fd89..29d97127ef9e 100644 --- a/src/raven.js +++ b/src/raven.js @@ -450,20 +450,24 @@ Raven.prototype = { ex.name = null; var stack = TraceKit.computeStackTrace(ex); - var prvCall = stack.stack[1]; + // 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]; - var fileurl = prvCall.url || ''; + 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( From 128175580b6c3ff352aeecf9055e4b72b59a6abb Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Mon, 9 Oct 2017 11:32:57 -0400 Subject: [PATCH 09/10] Wrapping returns in conditional used as template --- src/raven.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/raven.js b/src/raven.js index 29d97127ef9e..c6ab24749fd7 100644 --- a/src/raven.js +++ b/src/raven.js @@ -1470,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( { From c44222029cd0cd78d246efdad164c5ac2b261bc2 Mon Sep 17 00:00:00 2001 From: heroprotagonist Date: Mon, 9 Oct 2017 11:37:11 -0400 Subject: [PATCH 10/10] Make test assertions consistent --- test/raven.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/raven.test.js b/test/raven.test.js index a8f138740731..a5610bf2dc00 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -2670,13 +2670,13 @@ describe('Raven (public API)', function() { Raven._globalOptions.whitelistUrls = joinRegExp([/.+?host1.+/, /.+?host2.+/]); TraceKitStub.returns({stack: [{url: 'http://host1/'}, {url: 'http://host1/'}]}); Raven.captureMessage('Capture!'); - assert.equal(Raven._send.callCount, 1); + assert.isTrue(Raven._send.calledOnce); TraceKitStub.returns({stack: [{url: 'http://host2/'}, {url: 'http://host2/'}]}); Raven.captureMessage('Also capture!'); - assert.equal(Raven._send.callCount, 2); + assert.isTrue(Raven._send.calledTwice); TraceKitStub.returns({stack: [{url: 'http://host3/'}, {url: 'http://host3/'}]}); Raven.captureMessage('Do not capture!'); - assert.equal(Raven._send.callCount, 2); + assert.isTrue(Raven._send.calledTwice); }); it('should handle empty `whitelistUrls`', function() {