diff --git a/lib/agent/index.js b/lib/agent/index.js index a3eae1c..ca723ad 100644 --- a/lib/agent/index.js +++ b/lib/agent/index.js @@ -336,7 +336,7 @@ Agent.prototype.onCrash = function (data) { type: 'system-error', message: data.stackTrace.message, raw: { - stack: data.stackTrace.stack + stack: this.config.disableStackTrace ? undefined : data.stackTrace.stack } } }) diff --git a/lib/agent/index.spec.js b/lib/agent/index.spec.js index 4b43e09..c0ef429 100644 --- a/lib/agent/index.spec.js +++ b/lib/agent/index.spec.js @@ -160,6 +160,69 @@ describe('The Trace agent', function () { }) }) + it('reports crashes without stack traces if disableStackTrace is set', function () { + var sendStub = this.sandbox.stub(agent, '_send', function () {}) + var error = new Error('error') + error.stack = 'stacktrace' + this.sandbox.stub(agent, 'getMicrotime', function () { + return time + }) + this.sandbox.stub(agent, 'generateRequestId', function () { + return requestId + }) + this.sandbox.stub(agent, 'generateCommId', function () { + return parentCommId + }) + + agent.config.disableStackTrace = true + + agent.onCrash({ + stackTrace: error + }) + + expect(agent.reservoirSampler.getItems()).to.eql([ + { + requestId: requestId, + isSampled: false, + isForceSampled: true, + events: [ + { + type: 'sr', + time: time, + data: { + endpoint: 'stacktrace', + method: 'ERROR', + rpcId: parentCommId + } + }, + { + type: 'err', + time: time, + data: { + rpcId: parentCommId, + type: 'system-error', + message: error.message, + raw: { + stack: undefined + } + } + }, + { + type: 'ss', + time: time, + data: { + rpcId: parentCommId, + statusCode: 500 + } + } + ] + } + ]) + expect(sendStub).to.be.calledWith({ + isSync: true + }) + }) + it('does server receive when there is no parentId', function () { agent.serverReceive({ requestId: requestId, diff --git a/lib/utils/configReader.js b/lib/utils/configReader.js index 54c2107..3220f9a 100644 --- a/lib/utils/configReader.js +++ b/lib/utils/configReader.js @@ -59,6 +59,7 @@ ConfigReader.prototype._getEnvVarConfig = function () { serviceName: process.env.TRACE_SERVICE_NAME, configPath: process.env.TRACE_CONFIG_PATH, apiKey: process.env.TRACE_API_KEY, + disableStackTrace: process.env.TRACE_DISABLE_STACK_TRACE == true, // eslint-disable-line disableInstrumentations: process.env.TRACE_DISABLE_INSTRUMENTATIONS ? process.env.TRACE_DISABLE_INSTRUMENTATIONS.split(',') : []