-
Notifications
You must be signed in to change notification settings - Fork 0
/
otel-tracing.go
45 lines (35 loc) · 925 Bytes
/
otel-tracing.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
package tracing
import (
"context"
"go.opentelemetry.io/otel"
)
type headersCarrier map[string]interface{}
func (a headersCarrier) Get(key string) string {
v, ok := a[key]
if !ok {
return ""
}
return v.(string)
}
func (a headersCarrier) Set(key string, value string) {
a[key] = value
}
func (a headersCarrier) Keys() []string {
i := 0
r := make([]string, len(a))
for k := range a {
r[i] = k
i++
}
return r
}
// InjectAMQPHeaders injects the tracing from the context into the header map
func InjectAMQPHeaders(ctx context.Context) map[string]interface{} {
h := make(headersCarrier)
otel.GetTextMapPropagator().Inject(ctx, h)
return h
}
// ExtractAMQPHeaders extracts the tracing from the header and puts it into the context
func ExtractAMQPHeaders(ctx context.Context, headers map[string]interface{}) context.Context {
return otel.GetTextMapPropagator().Extract(ctx, headersCarrier(headers))
}