Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c4d88bb69 | |||
56288f46b1 |
23
tracer.go
23
tracer.go
@@ -7,7 +7,6 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/twmb/franz-go/pkg/kgo"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
@@ -61,7 +60,7 @@ func (m *hookTracer) OnFetchBatchRead(meta kgo.BrokerMetadata, topic string, _ i
|
||||
// hook.
|
||||
func (m *hookTracer) OnProduceRecordBuffered(r *kgo.Record) {
|
||||
// Set up span options.
|
||||
attrs := []attribute.KeyValue{
|
||||
attrs := []interface{}{
|
||||
semconv.MessagingSystemKey.String("kafka"),
|
||||
semconv.MessagingDestinationKindTopic,
|
||||
semconv.MessagingDestinationName(r.Topic),
|
||||
@@ -72,7 +71,7 @@ func (m *hookTracer) OnProduceRecordBuffered(r *kgo.Record) {
|
||||
attrs = append(attrs, semconv.MessagingKafkaClientIDKey.String(m.clientID))
|
||||
}
|
||||
opts := []tracer.SpanOption{
|
||||
tracer.WithSpanLabels(otel2Micro(attrs...)),
|
||||
tracer.WithSpanLabels(attrs...),
|
||||
tracer.WithSpanKind(tracer.SpanKindProducer),
|
||||
}
|
||||
// Start the "publish" span.
|
||||
@@ -111,7 +110,7 @@ func (m *hookTracer) OnProduceRecordUnbuffered(r *kgo.Record, err error) {
|
||||
// processing.
|
||||
func (m *hookTracer) OnFetchRecordBuffered(r *kgo.Record) {
|
||||
// Set up the span options.
|
||||
attrs := []attribute.KeyValue{
|
||||
attrs := []interface{}{
|
||||
semconv.MessagingSystemKey.String("kafka"),
|
||||
semconv.MessagingSourceKindTopic,
|
||||
semconv.MessagingSourceName(r.Topic),
|
||||
@@ -126,7 +125,7 @@ func (m *hookTracer) OnFetchRecordBuffered(r *kgo.Record) {
|
||||
attrs = append(attrs, semconv.MessagingKafkaConsumerGroupKey.String(m.group))
|
||||
}
|
||||
opts := []tracer.SpanOption{
|
||||
tracer.WithSpanLabels(otel2Micro(attrs...)),
|
||||
tracer.WithSpanLabels(attrs...),
|
||||
tracer.WithSpanKind(tracer.SpanKindConsumer),
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ func (m *hookTracer) OnFetchRecordUnbuffered(r *kgo.Record, _ bool) {
|
||||
// iteration of your processing for the record.
|
||||
func (m *hookTracer) WithProcessSpan(r *kgo.Record) (context.Context, tracer.Span) {
|
||||
// Set up the span options.
|
||||
attrs := []attribute.KeyValue{
|
||||
attrs := []interface{}{
|
||||
semconv.MessagingSystemKey.String("kafka"),
|
||||
semconv.MessagingSourceKindTopic,
|
||||
semconv.MessagingSourceName(r.Topic),
|
||||
@@ -176,7 +175,7 @@ func (m *hookTracer) WithProcessSpan(r *kgo.Record) (context.Context, tracer.Spa
|
||||
attrs = append(attrs, semconv.MessagingKafkaConsumerGroupKey.String(m.group))
|
||||
}
|
||||
opts := []tracer.SpanOption{
|
||||
tracer.WithSpanLabels(otel2Micro(attrs...)),
|
||||
tracer.WithSpanLabels(attrs...),
|
||||
tracer.WithSpanKind(tracer.SpanKindConsumer),
|
||||
}
|
||||
|
||||
@@ -187,7 +186,7 @@ func (m *hookTracer) WithProcessSpan(r *kgo.Record) (context.Context, tracer.Spa
|
||||
return m.tracer.Start(r.Context, r.Topic+" process", opts...)
|
||||
}
|
||||
|
||||
func maybeKeyAttr(attrs []attribute.KeyValue, r *kgo.Record) []attribute.KeyValue {
|
||||
func maybeKeyAttr(attrs []interface{}, r *kgo.Record) []interface{} {
|
||||
if r.Key == nil {
|
||||
return attrs
|
||||
}
|
||||
@@ -198,11 +197,3 @@ func maybeKeyAttr(attrs []attribute.KeyValue, r *kgo.Record) []attribute.KeyValu
|
||||
keykey = string(r.Key)
|
||||
return append(attrs, semconv.MessagingKafkaMessageKeyKey.String(keykey))
|
||||
}
|
||||
|
||||
func otel2Micro(attrs ...attribute.KeyValue) []interface{} {
|
||||
ret := make([]interface{}, 0, len(attrs))
|
||||
for _, a := range attrs {
|
||||
ret = append(ret, a.Key, a.Value)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
Reference in New Issue
Block a user