Skip to content

Commit f74498e

Browse files
HeroProtagonistkamilogorek
authored andcommitted
feat: Disable automatic breadcrumbs collection #782 (#1099)
1 parent 783a4ee commit f74498e

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed

docs/config.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Those configuration options are documented below:
209209
Enables/disables automatic collection of breadcrumbs. Possible values are:
210210

211211
* `true` (default)
212-
* `false` - all automatic breadcrumb collection disabled
212+
* `false` - all breadcrumb collection disabled
213213
* A dictionary of individual breadcrumb types that can be enabled/disabled:
214214

215215
.. code-block:: javascript
@@ -219,6 +219,7 @@ Those configuration options are documented below:
219219
'console': false, // console logging
220220
'dom': true, // DOM interactions, i.e. clicks/typing
221221
'location': false // url changes, including pushState/popState
222+
'sentry': true // sentry events
222223
}
223224
224225
.. describe:: maxBreadcrumbs

src/raven.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ Raven.prototype = {
178178
xhr: true,
179179
console: true,
180180
dom: true,
181-
location: true
181+
location: true,
182+
sentry: true
182183
};
183184

184185
var autoBreadcrumbs = globalOptions.autoBreadcrumbs;
@@ -1810,14 +1811,21 @@ Raven.prototype = {
18101811
}
18111812

18121813
var exception = data.exception && data.exception.values[0];
1813-
this.captureBreadcrumb({
1814-
category: 'sentry',
1815-
message: exception
1816-
? (exception.type ? exception.type + ': ' : '') + exception.value
1817-
: data.message,
1818-
event_id: data.event_id,
1819-
level: data.level || 'error' // presume error unless specified
1820-
});
1814+
1815+
// only capture 'sentry' breadcrumb is autoBreadcrumbs is truthy
1816+
if (
1817+
this._globalOptions.autoBreadcrumbs &&
1818+
this._globalOptions.autoBreadcrumbs.sentry
1819+
) {
1820+
this.captureBreadcrumb({
1821+
category: 'sentry',
1822+
message: exception
1823+
? (exception.type ? exception.type + ': ' : '') + exception.value
1824+
: data.message,
1825+
event_id: data.event_id,
1826+
level: data.level || 'error' // presume error unless specified
1827+
});
1828+
}
18211829

18221830
var url = this._globalEndpoint;
18231831
(globalOptions.transport || this._makeRequest).call(this, {

test/raven.test.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ describe('globals', function() {
802802
});
803803
});
804804

805-
it("should create and append 'sentry' breadcrumb", function() {
805+
it("should create and append 'sentry' breadcrumb when `_globalOptions.autoBreadcrumbs.sentry` is truthy", function() {
806806
this.sinon.stub(Raven, 'isSetup').returns(true);
807807
this.sinon.stub(Raven, '_makeRequest');
808808
this.sinon.stub(Raven, '_getHttpData').returns({
@@ -813,7 +813,10 @@ describe('globals', function() {
813813
Raven._globalProject = '2';
814814
Raven._globalOptions = {
815815
logger: 'javascript',
816-
maxMessageLength: 100
816+
maxMessageLength: 100,
817+
autoBreadcrumbs: {
818+
sentry: true
819+
}
817820
};
818821
Raven._breadcrumbs = [
819822
{
@@ -903,6 +906,41 @@ describe('globals', function() {
903906
]);
904907
});
905908

909+
it("should not create nor append 'sentry' breadcrumb when `_globalOptions.autoBreadcrumbs.sentry` is falsy", function() {
910+
this.sinon.stub(Raven, 'isSetup').returns(true);
911+
this.sinon.stub(Raven, '_makeRequest');
912+
this.sinon.stub(Raven, '_getHttpData').returns({
913+
url: 'http://localhost/?a=b',
914+
headers: {'User-Agent': 'lolbrowser'}
915+
});
916+
917+
Raven._globalProject = '2';
918+
Raven._globalOptions = {
919+
logger: 'javascript',
920+
maxMessageLength: 100,
921+
autoBreadcrumbs: false
922+
};
923+
924+
Raven._send({message: 'bar'});
925+
926+
assert.deepEqual(Raven._breadcrumbs, []);
927+
928+
Raven._send({message: 'foo', level: 'warning'});
929+
assert.deepEqual(Raven._breadcrumbs, []);
930+
931+
Raven._send({
932+
exception: {
933+
values: [
934+
{
935+
type: 'ReferenceError',
936+
value: 'foo is not defined'
937+
}
938+
]
939+
}
940+
});
941+
assert.deepEqual(Raven._breadcrumbs, []);
942+
});
943+
906944
it('should build a good data payload with a User', function() {
907945
this.sinon.stub(Raven, 'isSetup').returns(true);
908946
this.sinon.stub(Raven, '_makeRequest');
@@ -2187,7 +2225,8 @@ describe('Raven (public API)', function() {
21872225
xhr: true,
21882226
console: true,
21892227
dom: true,
2190-
location: true
2228+
location: true,
2229+
sentry: true
21912230
});
21922231
});
21932232

@@ -2208,6 +2247,7 @@ describe('Raven (public API)', function() {
22082247
xhr: true,
22092248
console: true,
22102249
dom: true,
2250+
sentry: true,
22112251
location: false /* ! */
22122252
});
22132253
});

0 commit comments

Comments
 (0)