-
Notifications
You must be signed in to change notification settings - Fork 14
/
otel_reader_wrapper.go
48 lines (39 loc) · 1.21 KB
/
otel_reader_wrapper.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
package kafka
import (
"context"
"github.com/Trendyol/otel-kafka-konsumer"
segmentio "github.com/segmentio/kafka-go"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"
)
type otelReaderWrapper struct {
r *otelkafkakonsumer.Reader
}
func NewOtelReaderWrapper(cfg *ConsumerConfig, reader *segmentio.Reader) (Reader, error) {
cfg.setDefaults()
newReader, err := otelkafkakonsumer.NewReader(
reader,
otelkafkakonsumer.WithTracerProvider(cfg.DistributedTracingConfiguration.TracerProvider),
otelkafkakonsumer.WithPropagator(cfg.DistributedTracingConfiguration.Propagator),
otelkafkakonsumer.WithAttributes(
[]attribute.KeyValue{
semconv.MessagingDestinationKindTopic,
semconv.MessagingKafkaClientIDKey.String(cfg.Reader.GroupID),
},
))
if err != nil {
return nil, err
}
return &otelReaderWrapper{
r: newReader,
}, nil
}
func (o *otelReaderWrapper) FetchMessage(ctx context.Context, msg *segmentio.Message) error {
return o.r.FetchMessage(ctx, msg)
}
func (o *otelReaderWrapper) Close() error {
return o.r.Close()
}
func (o *otelReaderWrapper) CommitMessages(messages []segmentio.Message) error {
return o.r.CommitMessages(context.Background(), messages...)
}