Skip to content

Commit f1aee78

Browse files
committed
fix(spans): remove sampling
1 parent 266520b commit f1aee78

4 files changed

Lines changed: 17 additions & 25 deletions

File tree

e2e/reportHttpRequest.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ test('should report http requests', function (t) {
6363
// http client request
6464
request
6565
.get('127.0.0.1:' + WEB_SERVER_PORT + '/test')
66+
.set('x-must-collect', '1')
6667
.end(function (err) {
6768
t.error(err, 'client sends request')
6869
})

lib/agent/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function Agent (options) {
2121
// config
2222
this.config = options.config
2323
this.collectInterval = this.config.collectInterval
24-
this.sampleRate = this.config.initialSampleRate
25-
this.sampleSize = this.config.sampleSize
2624

2725
this.totalRequestCount = 0
2826
this.mustCollectCount = 0
@@ -131,14 +129,13 @@ Agent.prototype.serverSend = function (data) {
131129
}
132130
})
133131

134-
span.isSampled = (1 / this.sampleRate) > Math.random()
135132
span.isForceSampled = span.isForceSampled || data.mustCollect === consts.MUST_COLLECT.ERROR
136133

137134
if (span.isForceSampled) {
138135
this.mustCollectCount += 1
139136
}
140137

141-
if ((span.isForceSampled || span.isSampled) && this.mustCollectCount <= MUST_COLLECT_LIMIT) {
138+
if (span.isForceSampled && (this.mustCollectCount <= MUST_COLLECT_LIMIT)) {
142139
this.spans.push(span)
143140
}
144141

@@ -392,13 +389,12 @@ Agent.prototype._send = function (options) {
392389
if (this.spans.length > 0) {
393390
var dataBag = {
394391
sample: {
395-
rate: this.sampleRate,
396-
totalRequestCount: this.totalRequestCount
392+
rate: 1,
393+
totalRequestCount: 1
397394
},
398395
spans: this.spans
399396
}
400397

401-
this.sampleRate = Math.floor(this.totalRequestCount / this.sampleSize) || 1
402398
this.totalRequestCount = 0
403399

404400
this.spans = []

lib/agent/index.spec.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ describe('The Trace agent', function () {
7878
expect(agent.totalRequestCount).to.eql(1)
7979
expect(agent.partials[transactionId]).to.eql({
8080
requestId: transactionId,
81-
isSampled: false,
8281
isForceSampled: false,
82+
isSampled: false,
8383
events: [{
8484
type: 'sr',
8585
time: time,
@@ -112,8 +112,8 @@ describe('The Trace agent', function () {
112112
expect(agent.totalRequestCount).to.eql(1)
113113
expect(agent.partials[transactionId]).to.eql({
114114
requestId: transactionId,
115-
isSampled: false,
116115
isForceSampled: false,
116+
isSampled: false,
117117
events: [{
118118
type: 'sr',
119119
time: time,
@@ -130,7 +130,6 @@ describe('The Trace agent', function () {
130130

131131
it('does server send', function () {
132132
var statusCode = 200
133-
agent.sampleRate = 1
134133
agent.serverReceive({
135134
id: transactionId,
136135
spanId: spanId,
@@ -144,7 +143,8 @@ describe('The Trace agent', function () {
144143
id: transactionId,
145144
spanId: spanId,
146145
responseTime: responseTime,
147-
statusCode: statusCode
146+
statusCode: statusCode,
147+
mustCollect: '1'
148148
})
149149

150150
expect(rpmMetrics.addResponseTime).to.have.been.calledWith(responseTime)
@@ -153,8 +153,8 @@ describe('The Trace agent', function () {
153153
expect(agent.partials).to.eql({})
154154
expect(agent.spans).to.eql([{
155155
requestId: transactionId,
156-
isSampled: true,
157-
isForceSampled: false,
156+
isForceSampled: true,
157+
isSampled: false,
158158
events: [{
159159
type: 'sr',
160160
time: time,
@@ -198,8 +198,8 @@ describe('The Trace agent', function () {
198198
expect(agent.spans).to.eql([])
199199
expect(agent.partials[transactionId]).to.eql({
200200
requestId: transactionId,
201-
isSampled: false,
202201
isForceSampled: false,
202+
isSampled: false,
203203
events: [{
204204
type: 'sr',
205205
time: time,
@@ -240,8 +240,8 @@ describe('The Trace agent', function () {
240240
expect(agent.spans).to.eql([])
241241
expect(agent.partials[transactionId]).to.eql({
242242
requestId: transactionId,
243-
isSampled: false,
244243
isForceSampled: false,
244+
isSampled: false,
245245
events: [{
246246
type: 'sr',
247247
time: time,
@@ -284,8 +284,8 @@ describe('The Trace agent', function () {
284284
expect(agent.spans).to.eql([])
285285
expect(agent.partials[transactionId]).to.eql({
286286
requestId: transactionId,
287-
isSampled: false,
288287
isForceSampled: false,
288+
isSampled: false,
289289
events: [{
290290
type: 'sr',
291291
time: time,
@@ -316,19 +316,16 @@ describe('The Trace agent', function () {
316316
2,
317317
3
318318
]
319-
agent.sampleRate = 2
320319
agent.totalRequestCount = 6
321-
agent.sampleSize = 10
322320
agent._send()
323321

324-
expect(agent.sampleRate).to.eql(1)
325322
expect(agent.totalRequestCount).to.eql(0)
326323
expect(collectorApi.sendSamples).to.be.calledWith({
324+
spans: [1, 2, 3],
327325
sample: {
328-
rate: 2,
329-
totalRequestCount: 6
330-
},
331-
spans: [1, 2, 3]
326+
rate: 1,
327+
totalRequestCount: 1
328+
}
332329
})
333330
})
334331

lib/config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ var url = require('url')
22
var config = {}
33

44
config.collectInterval = 2 * 60 * 1000
5-
config.sampleSize = 60
6-
config.initialSampleRate = 50
75

86
config.collectorLanguage = 'nodejs'
97
config.collectorApiUrl = 'https://trace-collector-api.risingstack.com'

0 commit comments

Comments
 (0)