Skip to content

Can enable synthetic traces globally via stacktrace: true (fixes #743) #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2016
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
4 changes: 3 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ Raven.prototype = {
return;
}

options = options || {};

var data = objectMerge({
message: msg + '' // Make sure it's actually a string
}, options);

if (options && options.stacktrace) {
if (this._globalOptions.stacktrace || (options && options.stacktrace)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need (options && here, now that options is checked above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tru

var ex;
// create a stack trace from this point; just trim
// off extra frames so they don't include this function call (or
Expand Down
54 changes: 37 additions & 17 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2045,28 +2045,48 @@ describe('Raven (public API)', function() {
});
});

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

function foo() {
Raven.captureMessage('foo', {
stacktrace: true
});
describe('synthetic traces', function () {
function assertSynthetic(frames) {
// Raven.captureMessage
var last = frames[frames.length - 1];
assert.isTrue(/(captureMessage|^\?)$/.test(last.function)); // loose equality check because differs per-browser
assert.equal(last.in_app, false);

// foo
var secondLast = frames[frames.length - 2];
assert.equal(secondLast.function, 'foo');
assert.equal(secondLast.in_app, true);
}

foo();
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
it('should get collected if stacktrace:true is passed via options', function () {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_send');

function foo() {
Raven.captureMessage('foo', {
stacktrace: true
});
}

foo();
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
assertSynthetic(frames);
});

it('should get collected if stacktrace:true is set via globalOptions', function () {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_send');

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

// foo
var secondLast = frames[frames.length - 2];
assert.equal(secondLast.function, 'foo');
assert.equal(secondLast.in_app, true);
foo();
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
assertSynthetic(frames);
});
});
});

Expand Down