-
Notifications
You must be signed in to change notification settings - Fork 53
/
propagation_lightstep.go
58 lines (47 loc) · 1.38 KB
/
propagation_lightstep.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
package lightstep
import (
"strconv"
"github.com/opentracing/opentracing-go"
)
const (
prefixTracerState = "ot-tracer-"
fieldNameTraceID = prefixTracerState + "traceid"
fieldNameSpanID = prefixTracerState + "spanid"
fieldNameSampled = prefixTracerState + "sampled"
)
// LightStepPropagator propagates context in the LightStep format
var LightStepPropagator lightstepPropagator
type lightstepPropagator struct{}
func lightstepTraceIDParser(v string) (uint64, uint64, error) {
traceID, err := strconv.ParseUint(v, 16, 64)
return traceID, 0, err
}
func (lightstepPropagator) Inject(
spanContext opentracing.SpanContext,
opaqueCarrier interface{},
) error {
sc, ok := spanContext.(SpanContext)
if !ok {
return opentracing.ErrInvalidSpanContext
}
propagator := textMapPropagator{
traceIDKey: fieldNameTraceID,
traceID: strconv.FormatUint(sc.TraceID, 16),
spanIDKey: fieldNameSpanID,
spanID: strconv.FormatUint(sc.SpanID, 16),
sampledKey: fieldNameSampled,
sampled: sc.Sampled,
}
return propagator.Inject(spanContext, opaqueCarrier)
}
func (lightstepPropagator) Extract(
opaqueCarrier interface{},
) (opentracing.SpanContext, error) {
propagator := textMapPropagator{
traceIDKey: fieldNameTraceID,
spanIDKey: fieldNameSpanID,
sampledKey: fieldNameSampled,
parseTraceID: lightstepTraceIDParser,
}
return propagator.Extract(opaqueCarrier)
}