Skip to content

Commit def19d2

Browse files
committed
fix(errorCount): limit error count to 20 per payload
1 parent 69bc334 commit def19d2

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

lib/agent/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var consts = require('../consts')
1111

1212
var REQUEST_ID = 'request-id'
1313
var SPAN_ID = 'span-id'
14+
var MUST_COLLECT_LIMIT = 20
1415

1516
function Agent (options) {
1617
debug('Agent is initializing...')
@@ -24,6 +25,7 @@ function Agent (options) {
2425
this.sampleSize = this.config.sampleSize
2526

2627
this.totalRequestCount = 0
28+
this.mustCollectCount = 0
2729

2830
// init required variables
2931
this.partials = {}
@@ -131,7 +133,11 @@ Agent.prototype.serverSend = function (data) {
131133
span.isSampled = (1 / this.sampleRate) > Math.random()
132134
span.isForceSampled = span.isForceSampled || data.mustCollect === consts.MUST_COLLECT.ERROR
133135

134-
if (span.isForceSampled || span.isSampled) {
136+
if (span.isForceSampled) {
137+
this.mustCollectCount += 1
138+
}
139+
140+
if ((span.isForceSampled || span.isSampled) && this.mustCollectCount <= MUST_COLLECT_LIMIT) {
135141
this.spans.push(span)
136142
}
137143

@@ -395,6 +401,7 @@ Agent.prototype._send = function (options) {
395401
this.totalRequestCount = 0
396402

397403
this.spans = []
404+
this.mustCollectCount = 0
398405
this.collectorApi.sendSamples(dataBag, options && options.isSync)
399406
}
400407
}

lib/agent/index.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,28 @@ describe('The Trace agent', function () {
331331
spans: [1, 2, 3]
332332
})
333333
})
334+
335+
it('limits must-collect count to 20', function () {
336+
var statusCode = 200
337+
agent.mustCollectCount = 20
338+
agent.serverReceive({
339+
id: transactionId,
340+
spanId: spanId,
341+
parentId: parentId,
342+
url: url,
343+
host: host,
344+
method: 'GET'
345+
})
346+
347+
agent.serverSend({
348+
id: transactionId,
349+
spanId: spanId,
350+
responseTime: responseTime,
351+
statusCode: statusCode,
352+
mustCollect: '1'
353+
})
354+
355+
expect(agent.spans).to.eql([])
356+
expect(agent.mustCollectCount).to.eql(21)
357+
})
334358
})

0 commit comments

Comments
 (0)