Skip to content

Commit f4d048a

Browse files
peteyyczgergelyke
authored andcommitted
fix(sampling): unify samping method
1 parent c8d91a1 commit f4d048a

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

lib/providers/httpTransaction/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ HttpTransaction.prototype.onClientReceive = function (data) {
146146
var trace = this._initTrace(data)
147147

148148
if (data.err) {
149-
trace.isSampled = true
149+
trace.isForceSampled = true
150150
}
151151

152152
trace.events.push({
@@ -172,11 +172,9 @@ HttpTransaction.prototype.onServerSend = function (data) {
172172
type: HttpTransaction.SERVER_SEND
173173
})
174174

175-
var isSampled = trace.isSampled || (1 / this.sampleRate) > Math.random()
176-
if (data.mustCollect || isSampled) {
177-
trace.isForceSampled = !!data.mustCollect
178-
delete trace.isSampled
179-
175+
trace.isSampled = (1 / this.sampleRate) > Math.random()
176+
trace.isForceSampled = trace.isForceSampled || !!data.mustCollect
177+
if (trace.isForceSampled || trace.isSampled) {
180178
this.traces.push(trace)
181179
}
182180

lib/providers/httpTransaction/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ describe('The HttpTransaction module', function () {
392392
span: url,
393393
host: host,
394394
trace: id,
395+
isSampled: true,
395396
isForceSampled: false,
396397
service: service,
397398
statusCode: 301,

0 commit comments

Comments
 (0)