Skip to content

Commit 93afbd2

Browse files
committed
feat(security): option to opt-out of stacktrace collection
1 parent 701ff6d commit 93afbd2

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

lib/agent/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Agent.prototype.onCrash = function (data) {
336336
type: 'system-error',
337337
message: data.stackTrace.message,
338338
raw: {
339-
stack: data.stackTrace.stack
339+
stack: this.config.disableStackTrace ? undefined : data.stackTrace.stack
340340
}
341341
}
342342
})

lib/agent/index.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,69 @@ describe('The Trace agent', function () {
160160
})
161161
})
162162

163+
it('reports crashes without stack traces if disableStackTrace is set', function () {
164+
var sendStub = this.sandbox.stub(agent, '_send', function () {})
165+
var error = new Error('error')
166+
error.stack = 'stacktrace'
167+
this.sandbox.stub(agent, 'getMicrotime', function () {
168+
return time
169+
})
170+
this.sandbox.stub(agent, 'generateRequestId', function () {
171+
return requestId
172+
})
173+
this.sandbox.stub(agent, 'generateCommId', function () {
174+
return parentCommId
175+
})
176+
177+
agent.config.disableStackTrace = true
178+
179+
agent.onCrash({
180+
stackTrace: error
181+
})
182+
183+
expect(agent.reservoirSampler.getItems()).to.eql([
184+
{
185+
requestId: requestId,
186+
isSampled: false,
187+
isForceSampled: true,
188+
events: [
189+
{
190+
type: 'sr',
191+
time: time,
192+
data: {
193+
endpoint: 'stacktrace',
194+
method: 'ERROR',
195+
rpcId: parentCommId
196+
}
197+
},
198+
{
199+
type: 'err',
200+
time: time,
201+
data: {
202+
rpcId: parentCommId,
203+
type: 'system-error',
204+
message: error.message,
205+
raw: {
206+
stack: undefined
207+
}
208+
}
209+
},
210+
{
211+
type: 'ss',
212+
time: time,
213+
data: {
214+
rpcId: parentCommId,
215+
statusCode: 500
216+
}
217+
}
218+
]
219+
}
220+
])
221+
expect(sendStub).to.be.calledWith({
222+
isSync: true
223+
})
224+
})
225+
163226
it('does server receive when there is no parentId', function () {
164227
agent.serverReceive({
165228
requestId: requestId,

lib/utils/configReader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ConfigReader.prototype._getEnvVarConfig = function () {
5959
serviceName: process.env.TRACE_SERVICE_NAME,
6060
configPath: process.env.TRACE_CONFIG_PATH,
6161
apiKey: process.env.TRACE_API_KEY,
62+
disableStackTrace: process.env.TRACE_DISABLE_STACK_TRACE == true, // eslint-disable-line
6263
disableInstrumentations: process.env.TRACE_DISABLE_INSTRUMENTATIONS
6364
? process.env.TRACE_DISABLE_INSTRUMENTATIONS.split(',')
6465
: []

0 commit comments

Comments
 (0)