Skip to content

Commit 3b4c4a1

Browse files
author
Stephen Belanger
committed
feat(context): add setting sampled flag in create
1 parent 3c7c12a commit 3b4c4a1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/instrumentation/context.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ class TraceContext {
2424
this.parentId = parentId
2525
}
2626

27-
static create () {
27+
static create (sampled = false) {
2828
const bytes = crypto.randomBytes(24)
29+
const flags = Buffer.alloc(1)
30+
31+
// Load sampled flag into first bit of flags
32+
if (sampled) {
33+
flags[0] |= 0x01
34+
} else {
35+
flags[0] &= ~0x01
36+
}
2937

3038
return new TraceContext({
3139
version: Buffer.alloc(1),
3240
traceId: bytes.slice(0, 16),
3341
id: bytes.slice(16),
34-
flags: Buffer.alloc(1)
42+
flags: flags
3543
})
3644
}
3745

0 commit comments

Comments
 (0)