-
Notifications
You must be signed in to change notification settings - Fork 171
/
TraceId.js
93 lines (78 loc) · 1.83 KB
/
TraceId.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2020 The OpenZipkin Authors; licensed to You under the Apache License, Version 2.0.
const {
Some,
None,
verifyIsOptional,
verifyIsNotOptional,
isOptional
} = require('../option');
const T = new Some(true);
class TraceId {
constructor(params) {
const {
spanId,
traceId = spanId,
parentId = None,
flags = 0, // deprecated
debug = flags === 1,
sampled = None,
shared = false
} = params;
verifyIsNotOptional(spanId);
verifyIsOptional(parentId);
verifyIsOptional(sampled);
// support old signatures which allowed traceId to be optional
if (isOptional(traceId)) {
this._traceId = traceId.getOrElse(spanId);
} else if (typeof traceId === 'undefined' || traceId === null) {
this._traceId = spanId;
} else {
this._traceId = traceId;
}
this._parentId = parentId;
this._spanId = spanId;
this._sampled = debug ? T : sampled;
this._debug = debug;
this._shared = shared;
}
get traceId() {
return this._traceId;
}
get parentSpanId() {
return this._parentId;
}
/**
* Please use parentSpanId instead as this can return confusing results (the span ID when absent).
*
* @deprecated since version v0.19
*/
get parentId() {
return this._parentId.getOrElse(this._spanId);
}
get spanId() {
return this._spanId;
}
get sampled() {
return this._sampled;
}
/**
* Please use isDebug instead.
*
* @deprecated since version v0.19
*/
get flags() {
return this._debug ? 1 : 0;
}
isDebug() {
return this._debug;
}
isShared() {
return this._shared;
}
toString() {
return `TraceId(spanId=${this.spanId.toString()}`
+ `, parentSpanId=${this.parentSpanId.toString()}`
+ `, traceId=${this.traceId.toString()})`;
}
}
module.exports = TraceId;