-
Notifications
You must be signed in to change notification settings - Fork 1
/
carrier.go
57 lines (47 loc) · 1.05 KB
/
carrier.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
package zkafka
import (
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"go.opentelemetry.io/otel/propagation"
)
var _ propagation.TextMapCarrier = (*kMsgCarrier)(nil)
var _ propagation.TextMapCarrier = (*msgCarrier)(nil)
type kMsgCarrier struct {
msg *kafka.Message
}
func (c *kMsgCarrier) Get(key string) string {
for _, h := range c.msg.Headers {
if h.Key == key {
return string(h.Value)
}
}
return ""
}
func (c *kMsgCarrier) Keys() []string {
keys := make([]string, 0, len(c.msg.Headers))
for _, v := range c.msg.Headers {
keys = append(keys, v.Key)
}
return keys
}
func (c *kMsgCarrier) Set(key, val string) {
addStringAttribute(c.msg, key, []byte(val))
}
type msgCarrier struct {
msg *Message
}
func (c *msgCarrier) Get(key string) string {
for k, v := range c.msg.Headers {
if k == key {
return string(v)
}
}
return ""
}
func (c *msgCarrier) Keys() []string {
keys := make([]string, 0, len(c.msg.Headers))
for k := range c.msg.Headers {
keys = append(keys, k)
}
return keys
}
func (c *msgCarrier) Set(_, _ string) {}