Skip to content

Commit 592bfce

Browse files
authored
Can enable synthetic traces globally via stacktrace: true (#763)
1 parent b1cf42f commit 592bfce

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

src/raven.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,13 @@ Raven.prototype = {
363363
return;
364364
}
365365

366+
options = options || {};
367+
366368
var data = objectMerge({
367369
message: msg + '' // Make sure it's actually a string
368370
}, options);
369371

370-
if (options && options.stacktrace) {
372+
if (this._globalOptions.stacktrace || (options && options.stacktrace)) {
371373
var ex;
372374
// create a stack trace from this point; just trim
373375
// off extra frames so they don't include this function call (or

test/raven.test.js

+37-17
Original file line numberDiff line numberDiff line change
@@ -2059,28 +2059,48 @@ describe('Raven (public API)', function() {
20592059
});
20602060
});
20612061

2062-
it('should include a synthetic stacktrace if stacktrace:true is passed', function () {
2063-
this.sinon.stub(Raven, 'isSetup').returns(true);
2064-
this.sinon.stub(Raven, '_send');
20652062

2066-
function foo() {
2067-
Raven.captureMessage('foo', {
2068-
stacktrace: true
2069-
});
2063+
describe('synthetic traces', function () {
2064+
function assertSynthetic(frames) {
2065+
// Raven.captureMessage
2066+
var last = frames[frames.length - 1];
2067+
assert.isTrue(/(captureMessage|^\?)$/.test(last.function)); // loose equality check because differs per-browser
2068+
assert.equal(last.in_app, false);
2069+
2070+
// foo
2071+
var secondLast = frames[frames.length - 2];
2072+
assert.equal(secondLast.function, 'foo');
2073+
assert.equal(secondLast.in_app, true);
20702074
}
20712075

2072-
foo();
2073-
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
2076+
it('should get collected if stacktrace:true is passed via options', function () {
2077+
this.sinon.stub(Raven, 'isSetup').returns(true);
2078+
this.sinon.stub(Raven, '_send');
2079+
2080+
function foo() {
2081+
Raven.captureMessage('foo', {
2082+
stacktrace: true
2083+
});
2084+
}
2085+
2086+
foo();
2087+
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
2088+
assertSynthetic(frames);
2089+
});
2090+
2091+
it('should get collected if stacktrace:true is set via globalOptions', function () {
2092+
this.sinon.stub(Raven, 'isSetup').returns(true);
2093+
this.sinon.stub(Raven, '_send');
20742094

2075-
// Raven.captureMessage
2076-
var last = frames[frames.length - 1];
2077-
assert.isTrue(/(captureMessage|^\?)$/.test(last.function)); // loose equality check because differs per-browser
2078-
assert.equal(last.in_app, false);
2095+
Raven._globalOptions.stacktrace = true;
2096+
function foo() {
2097+
Raven.captureMessage('foo');
2098+
}
20792099

2080-
// foo
2081-
var secondLast = frames[frames.length - 2];
2082-
assert.equal(secondLast.function, 'foo');
2083-
assert.equal(secondLast.in_app, true);
2100+
foo();
2101+
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
2102+
assertSynthetic(frames);
2103+
});
20842104
});
20852105
});
20862106

0 commit comments

Comments
 (0)