-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracestate_parser.go
63 lines (51 loc) · 1.23 KB
/
tracestate_parser.go
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
package bugsnagperformance
import (
"strconv"
"strings"
"go.opentelemetry.io/otel/trace"
)
type parsedTracestate struct {
version *string
rValue32 *uint32
rValue64 *uint64
}
func (pts parsedTracestate) isValid() bool {
return pts.version != nil && (pts.rValue32 != nil || pts.rValue64 != nil)
}
func (pts parsedTracestate) isValue32() bool {
return pts.rValue32 != nil
}
func (pts parsedTracestate) getRValue32() uint32 {
return *(pts.rValue32)
}
func (pts parsedTracestate) getRValue64() uint64 {
return *(pts.rValue64)
}
type tracestateParser struct{}
func (tsp *tracestateParser) parse(tracestate trace.TraceState) parsedTracestate {
state := parsedTracestate{}
sbValues := tracestate.Get("sb")
if sbValues == "" {
return state
}
sbParts := strings.Split(sbValues, ";")
for _, pair := range sbParts {
splitPair := strings.Split(pair, ":")
switch splitPair[0] {
case "v":
state.version = &splitPair[1]
case "r32":
parsedR, err := strconv.ParseUint(splitPair[1], 10, 32)
if err == nil {
parsedR32 := uint32(parsedR)
state.rValue32 = &parsedR32
}
case "r64":
parsedR64, err := strconv.ParseUint(splitPair[1], 10, 64)
if err == nil {
state.rValue64 = &parsedR64
}
}
}
return state
}