forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampling-flag.js
34 lines (25 loc) · 843 Bytes
/
sampling-flag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
//https://github.com/naver/pinpoint/blob/ab07664e2ed944e90aa9c44f7e39597f39264c2b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultTraceHeaderReader.java#L78
const SAMPLING_RATE_PREFIX = "s"
const SAMPLING_RATE_FALSE = SAMPLING_RATE_PREFIX + "0"
class SamplingFlag {
isSamplingFlag(samplingFlag) {
if (samplingFlag == null) {
return true
}
if (samplingFlag.startsWith && samplingFlag.startsWith(SAMPLING_RATE_PREFIX)) {
return SAMPLING_RATE_FALSE != samplingFlag
}
return true
}
samplingRateFalse() {
return SAMPLING_RATE_FALSE
}
}
const samplingFlag = new SamplingFlag()
module.exports = samplingFlag