-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta.go
45 lines (33 loc) · 970 Bytes
/
meta.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 tracer
import (
"context"
"github.com/alexfalkowski/go-service/transport/nsq/message"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
)
func extract(ctx context.Context, h message.Headers) context.Context {
prop := otel.GetTextMapPropagator()
return prop.Extract(ctx, headerCarrier(h))
}
func inject(ctx context.Context, h message.Headers) {
prop := otel.GetTextMapPropagator()
prop.Inject(ctx, headerCarrier(h))
}
type headerCarrier message.Headers
var _ propagation.TextMapCarrier = &headerCarrier{}
// Get returns the value associated with the passed key.
func (hc headerCarrier) Get(key string) string {
return hc[key]
}
// Set stores the key-value pair.
func (hc headerCarrier) Set(key string, value string) {
hc[key] = value
}
// Keys lists the keys stored in this carrier.
func (hc headerCarrier) Keys() []string {
keys := make([]string, 0, len(hc))
for k := range hc {
keys = append(keys, k)
}
return keys
}