From 08bb29dd33c326b0c36086d9e2e5df93512301a5 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Wed, 11 Nov 2015 14:28:13 -0800 Subject: [PATCH 1/2] Support setting Error.stackTraceLimit automatically In V8, `Error.stack` is truncated with a default `Error.stackTraceLimit` of 10. So we want to expose this and set it to Infinity to capture it all. --- example/scratch.js | 16 ++++++++++++++++ src/raven.js | 8 ++++++-- test/raven.test.js | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/example/scratch.js b/example/scratch.js index 9f1fa27dbcd9..68edcdb7b815 100644 --- a/example/scratch.js +++ b/example/scratch.js @@ -45,3 +45,19 @@ function showDialog() { broken(); Raven.showReportDialog(); } + +function a() { b(); } +function b() { c(); } +function c() { d(); } +function d() { e(); } +function e() { f(); } +function f() { g(); } +function g() { h(); } +function h() { i(); } +function i() { j(); } +function j() { k(); } +function k() { l(); } +function l() { m(); } +function m() { n(); } +function n() { o(); } +function o() { throw new Error('dang'); } diff --git a/src/raven.js b/src/raven.js index 7cbbdc6e7cc3..bd1dbce26dae 100644 --- a/src/raven.js +++ b/src/raven.js @@ -45,10 +45,12 @@ function Raven() { includePaths: [], crossOrigin: 'anonymous', collectWindowErrors: true, - maxMessageLength: 0 + maxMessageLength: 0, + stackTraceLimit: Infinity }; this._ignoreOnError = 0; this._isRavenInstalled = false; + this._originalErrorStackTraceLimit = Error.stackTraceLimit; // capture references to window.console *and* all its methods first // before the console plugin has a chance to monkey patch this._originalConsole = window.console || {}; @@ -164,6 +166,7 @@ Raven.prototype = { this._isRavenInstalled = true; } + Error.stackTraceLimit = this._globalOptions.stackTraceLimit; return this; }, @@ -269,6 +272,7 @@ Raven.prototype = { this._restoreBuiltIns(); + Error.stackTraceLimit = this._originalErrorStackTraceLimit; this._isRavenInstalled = false; return this; @@ -757,7 +761,7 @@ Raven.prototype = { stackInfo.message, stackInfo.url, stackInfo.lineno, - frames, + frames.slice(0, this._globalOptions.stackTraceLimit), options ); }, diff --git a/test/raven.test.js b/test/raven.test.js index ba2bf7036771..588f8bf7322a 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1449,6 +1449,29 @@ describe('globals', function() { 'new ', 'hey', 'http://example.com', 10, [], undefined ]); }); + + it('should trim number of frames based on stackTraceLimit', function() { + var frame = {url: 'http://example.com'}; + this.sinon.stub(Raven, '_normalizeFrame').returns(frame); + this.sinon.stub(Raven, '_processException'); + + var stackInfo = { + name: 'Matt', + message: 'hey', + url: 'http://example.com', + lineno: 10, + stack: [ + frame, frame + ] + }; + + Raven._globalOptions.stackTraceLimit = 1; + + Raven._handleStackInfo(stackInfo); + assert.deepEqual(Raven._processException.lastCall.args, [ + 'Matt', 'hey', 'http://example.com', 10, [frame], undefined + ]); + }); }); }); From 5871cc10302cb1945db39c33fcda44f70a7f026e Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Wed, 30 Dec 2015 19:01:42 -0500 Subject: [PATCH 2/2] stack limit of 50, not Infinity We don't have infinite room to send data, we only have 100KB, even for POST, so we need to be a little bit conservative. 50 should be enough for most cases. If we need to handle more, we'll need to implement compression on the client so our packet is less than 100KB like our other server side clients. --- src/raven.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raven.js b/src/raven.js index bd1dbce26dae..3a2ef40f507d 100644 --- a/src/raven.js +++ b/src/raven.js @@ -46,7 +46,7 @@ function Raven() { crossOrigin: 'anonymous', collectWindowErrors: true, maxMessageLength: 0, - stackTraceLimit: Infinity + stackTraceLimit: 50 }; this._ignoreOnError = 0; this._isRavenInstalled = false;