From 5920f122d53b70e6ebe8b49f986c47271b0354d0 Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Thu, 21 Apr 2016 15:25:31 -0700 Subject: [PATCH] Don't capture breadcrumbs for Sentry XHRs --- src/raven.js | 15 ++++++++++----- test/integration/test.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/raven.js b/src/raven.js index 63cc2cc332ea..f5a85ca6242f 100644 --- a/src/raven.js +++ b/src/raven.js @@ -777,11 +777,16 @@ Raven.prototype = { var xhrproto = XMLHttpRequest.prototype; fill(xhrproto, 'open', function(origOpen) { return function (method, url) { // preserve arity - this.__raven_xhr = { - method: method, - url: url, - status_code: null - }; + + // if Sentry key appears in URL, don't capture + if (url.indexOf(self._globalKey) === -1) { + this.__raven_xhr = { + method: method, + url: url, + status_code: null + }; + } + return origOpen.apply(this, arguments); }; }); diff --git a/test/integration/test.js b/test/integration/test.js index 396288bf5a20..0709c6dc52d0 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -306,7 +306,6 @@ describe('integration', function () { iframeExecute(iframe, done, function () { - // some browsers trigger onpopstate for load / reset breadcrumb state Raven._breadcrumbs = []; @@ -372,6 +371,34 @@ describe('integration', function () { ); }); + it('should NOT capture breadcrumbs from XMLHttpRequests to the Sentry store endpoint', function (done) { + var iframe = this.iframe; + iframeExecute(iframe, done, + function () { + // some browsers trigger onpopstate for load / reset breadcrumb state + Raven._breadcrumbs = []; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'https://example.com/api/1/store/?sentry_key=public'); + xhr.setRequestHeader('Content-type', 'application/json'); + xhr.onreadystatechange = function () { + // don't fire `done` handler until at least *one* onreadystatechange + // has occurred (doesn't actually need to finish) + if (xhr.readyState === 4) { + setTimeout(done); + } + }; + xhr.send(); + }, + function () { + var Raven = iframe.contentWindow.Raven, + breadcrumbs = Raven._breadcrumbs; + + assert.equal(breadcrumbs.length, 0); + } + ); + }); + it('should record a mouse click on element WITH click handler present', function (done) { var iframe = this.iframe;