Skip to content

Commit 2210615

Browse files
authored
Introduce maxBreadcrumbs, increase default (and max) limit to 100 (#685)
1 parent 2c97c64 commit 2210615

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

docs/config.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ Those configuration options are documented below:
167167
By default, Raven does not truncate messages. If you need to truncate
168168
characters for whatever reason, you may set this to limit the length.
169169

170+
.. describe:: maxBreadcrumbs
171+
172+
By default, Raven captures as many as 100 breadcrumb entries. If you find this too noisy, you can reduce this
173+
number by setting `maxBreadcrumbs`. Note that this number cannot be set higher than the default of 100.
174+
170175
.. describe:: transport
171176

172177
Override the default HTTP data transport handler.

src/raven.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ function Raven() {
6565
this._startTime = now();
6666
this._wrappedBuiltIns = [];
6767
this._breadcrumbs = [];
68-
this._breadcrumbLimit = 20;
6968
this._lastCapturedEvent = null;
7069
this._keypressTimeout;
7170
this._location = window.location;
@@ -137,6 +136,7 @@ Raven.prototype = {
137136
this._globalOptions.ignoreUrls = this._globalOptions.ignoreUrls.length ? joinRegExp(this._globalOptions.ignoreUrls) : false;
138137
this._globalOptions.whitelistUrls = this._globalOptions.whitelistUrls.length ? joinRegExp(this._globalOptions.whitelistUrls) : false;
139138
this._globalOptions.includePaths = joinRegExp(this._globalOptions.includePaths);
139+
this._globalOptions.maxBreadcrumbs = Math.max(0, Math.min(this._globalOptions.maxBreadcrumbs || 100, 100)); // default and hard limit is 100
140140

141141
this._globalKey = uri.user;
142142
this._globalSecret = uri.pass && uri.pass.substr(1);
@@ -358,7 +358,7 @@ Raven.prototype = {
358358
}, obj);
359359

360360
this._breadcrumbs.push(crumb);
361-
if (this._breadcrumbs.length > this._breadcrumbLimit) {
361+
if (this._breadcrumbs.length > this._globalOptions.maxBreadcrumbs) {
362362
this._breadcrumbs.shift();
363363
}
364364
},

test/raven.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,28 @@ describe('Raven (public API)', function() {
15781578
assert.isFalse(TraceKit.collectWindowErrors);
15791579
});
15801580
});
1581+
1582+
describe('maxBreadcrumbs', function () {
1583+
it('should override the default', function () {
1584+
Raven.config(SENTRY_DSN, { maxBreadcrumbs: 50 });
1585+
assert.equal(Raven._globalOptions.maxBreadcrumbs, 50);
1586+
});
1587+
1588+
it('should not permit maxBreadcrumbs above 100', function () {
1589+
Raven.config(SENTRY_DSN, { maxBreadcrumbs: 200 });
1590+
assert.equal(Raven._globalOptions.maxBreadcrumbs, 100);
1591+
});
1592+
1593+
it('should not permit maxBreadcrumbs below 0', function () {
1594+
Raven.config(SENTRY_DSN, { maxBreadcrumbs: -1 });
1595+
assert.equal(Raven._globalOptions.maxBreadcrumbs, 0);
1596+
});
1597+
1598+
it('should set maxBreadcrumbs to the default if not provided', function () {
1599+
Raven.config(SENTRY_DSN);
1600+
assert.equal(Raven._globalOptions.maxBreadcrumbs, 100);
1601+
});
1602+
});
15811603
});
15821604

15831605
describe('.wrap', function() {
@@ -2063,7 +2085,7 @@ describe('Raven (public API)', function() {
20632085
});
20642086

20652087
it('should dequeue the oldest breadcrumb when over limit', function() {
2066-
Raven._breadcrumbLimit = 5;
2088+
Raven._globalOptions.maxBreadcrumbs = 5;
20672089
Raven._breadcrumbs = [
20682090
{ message: '1', timestamp: 0.1 },
20692091
{ message: '2', timestamp: 0.1 },

0 commit comments

Comments
 (0)