Skip to content
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
3 changes: 2 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Those configuration options are documented below:
Enables/disables automatic collection of breadcrumbs. Possible values are:

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

.. code-block:: javascript
Expand All @@ -219,6 +219,7 @@ Those configuration options are documented below:
'console': false, // console logging
'dom': true, // DOM interactions, i.e. clicks/typing
'location': false // url changes, including pushState/popState
'sentry': true // sentry events
}

.. describe:: maxBreadcrumbs
Expand Down
26 changes: 17 additions & 9 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ Raven.prototype = {
xhr: true,
console: true,
dom: true,
location: true
location: true,
sentry: true
};

var autoBreadcrumbs = globalOptions.autoBreadcrumbs;
Expand Down Expand Up @@ -1810,14 +1811,21 @@ Raven.prototype = {
}

var exception = data.exception && data.exception.values[0];
this.captureBreadcrumb({
category: 'sentry',
message: exception
? (exception.type ? exception.type + ': ' : '') + exception.value
: data.message,
event_id: data.event_id,
level: data.level || 'error' // presume error unless specified
});

// only capture 'sentry' breadcrumb is autoBreadcrumbs is truthy
if (
this._globalOptions.autoBreadcrumbs &&
this._globalOptions.autoBreadcrumbs.sentry
) {
this.captureBreadcrumb({
category: 'sentry',
message: exception
? (exception.type ? exception.type + ': ' : '') + exception.value
: data.message,
event_id: data.event_id,
level: data.level || 'error' // presume error unless specified
});
}

var url = this._globalEndpoint;
(globalOptions.transport || this._makeRequest).call(this, {
Expand Down
46 changes: 43 additions & 3 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ describe('globals', function() {
});
});

it("should create and append 'sentry' breadcrumb", function() {
it("should create and append 'sentry' breadcrumb when `_globalOptions.autoBreadcrumbs.sentry` is truthy", function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_makeRequest');
this.sinon.stub(Raven, '_getHttpData').returns({
Expand All @@ -813,7 +813,10 @@ describe('globals', function() {
Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100
maxMessageLength: 100,
autoBreadcrumbs: {
sentry: true
}
};
Raven._breadcrumbs = [
{
Expand Down Expand Up @@ -903,6 +906,41 @@ describe('globals', function() {
]);
});

it("should not create nor append 'sentry' breadcrumb when `_globalOptions.autoBreadcrumbs.sentry` is falsy", function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_makeRequest');
this.sinon.stub(Raven, '_getHttpData').returns({
url: 'http://localhost/?a=b',
headers: {'User-Agent': 'lolbrowser'}
});

Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100,
autoBreadcrumbs: false
};

Raven._send({message: 'bar'});

assert.deepEqual(Raven._breadcrumbs, []);

Raven._send({message: 'foo', level: 'warning'});
assert.deepEqual(Raven._breadcrumbs, []);

Raven._send({
exception: {
values: [
{
type: 'ReferenceError',
value: 'foo is not defined'
}
]
}
});
assert.deepEqual(Raven._breadcrumbs, []);
});

it('should build a good data payload with a User', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_makeRequest');
Expand Down Expand Up @@ -2187,7 +2225,8 @@ describe('Raven (public API)', function() {
xhr: true,
console: true,
dom: true,
location: true
location: true,
sentry: true
});
});

Expand All @@ -2208,6 +2247,7 @@ describe('Raven (public API)', function() {
xhr: true,
console: true,
dom: true,
sentry: true,
location: false /* ! */
});
});
Expand Down