Skip to content

Commit

Permalink
feat(security): option to opt-out of stacktrace collection
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyke committed Aug 12, 2016
1 parent 701ff6d commit 93afbd2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
})
Expand Down
63 changes: 63 additions & 0 deletions lib/agent/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/configReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
: []
Expand Down

0 comments on commit 93afbd2

Please sign in to comment.