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
15 changes: 15 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ Those configuration options are documented below:

If set to `true`, Raven.js outputs some light debugging information onto the console.


.. describe:: instrument

Enables/disables instrumentation of globals. Possible values are:

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

.. code-block:: javascript

instrument: {
'tryCatch': true, // Instruments timers and event targets
}

Putting it all together
-----------------------

Expand Down
21 changes: 19 additions & 2 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Raven() {
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1
};
this._ignoreOnError = 0;
Expand Down Expand Up @@ -155,6 +156,18 @@ Raven.prototype = {
}
globalOptions.autoBreadcrumbs = autoBreadcrumbs;

var instrumentDefaults = {
tryCatch: true
};

var instrument = globalOptions.instrument;
if ({}.toString.call(instrument) === '[object Object]') {
instrument = objectMerge(instrumentDefaults, instrument);
} else if (instrument !== false) {
instrument = instrumentDefaults;
}
globalOptions.instrument = instrument;

TraceKit.collectWindowErrors = !!globalOptions.collectWindowErrors;

// return for chaining
Expand All @@ -175,7 +188,10 @@ Raven.prototype = {
TraceKit.report.subscribe(function () {
self._handleOnErrorStackInfo.apply(self, arguments);
});
self._instrumentTryCatch();
if (self._globalOptions.instrument && self._globalOptions.instrument.tryCatch) {
self._instrumentTryCatch();
}

if (self._globalOptions.autoBreadcrumbs)
self._instrumentBreadcrumbs();

Expand Down Expand Up @@ -853,7 +869,8 @@ Raven.prototype = {
},

/**
* Install any queued plugins
* Wrap timer functions and event targets to catch errors and provide
* better metadata.
*/
_instrumentTryCatch: function() {
var self = this;
Expand Down
51 changes: 51 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,33 @@ describe('Raven (public API)', function() {
});
});

describe('instrument', function () {
it('should convert `true` to a dictionary of enabled instrument features', function () {
Raven.config(SENTRY_DSN);
assert.deepEqual(Raven._globalOptions.instrument, {
tryCatch: true,
});
});

it('should leave false as-is', function () {
Raven.config(SENTRY_DSN, {
instrument: false
});
assert.equal(Raven._globalOptions.instrument, false);
});

it('should merge objects with the default instrument settings', function () {
Raven.config(SENTRY_DSN, {
instrument: {
tryCatch: false
}
});
assert.deepEqual(Raven._globalOptions.instrument, {
tryCatch: false,
});
});
});

describe('autoBreadcrumbs', function () {
it('should convert `true` to a dictionary of enabled breadcrumb features', function () {
Raven.config(SENTRY_DSN);
Expand Down Expand Up @@ -2936,6 +2963,30 @@ describe('install/uninstall', function () {
document.addEventListener = temp;
});

it('should instrument try/catch by default', function () {
this.sinon.stub(Raven, '_instrumentTryCatch');
Raven.config(SENTRY_DSN).install();
assert.isTrue(Raven._instrumentTryCatch.calledOnce);
});

it('should not instrument try/catch if instrument is false', function () {
this.sinon.stub(Raven, '_instrumentTryCatch');
Raven.config(SENTRY_DSN, {
instrument: false
}).install();
assert.isFalse(Raven._instrumentTryCatch.called);
});

it('should not instrument try/catch if instrument.tryCatch is false', function () {
this.sinon.stub(Raven, '_instrumentTryCatch');
Raven.config(SENTRY_DSN, {
instrument: {
tryCatch: false
}
}).install();
assert.isFalse(Raven._instrumentTryCatch.called);
});

it('should instrument breadcrumbs by default', function () {
this.sinon.stub(Raven, '_instrumentBreadcrumbs');
Raven.config(SENTRY_DSN).install();
Expand Down
7 changes: 7 additions & 0 deletions typescript/raven.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ interface RavenOptions {

/** Override the default HTTP data transport handler. */
transport?: (options: RavenTransportOptions) => void;

/** Enables/disables instrumentation of globals. */
instrument?: boolean | RavenInstrumentationOptions;
}

interface RavenInstrumentationOptions {
tryCatch?: boolean;
}

interface RavenStatic {
Expand Down