From a942f62b3b9c12d3ac5d9b844332327ae49d7906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catt=C4=AB=20Cr=C5=ABd=C4=93l=C4=93s?= <17695588+wzy9607@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:37:40 +0800 Subject: [PATCH] feat: use semconv v1.26.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cattī Crūdēlēs <17695588+wzy9607@users.noreply.github.com> --- acknowledger.go | 7 +++++-- channel.go | 15 +++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/acknowledger.go b/acknowledger.go index a12efec..905c0f8 100644 --- a/acknowledger.go +++ b/acknowledger.go @@ -4,6 +4,7 @@ import ( "context" "go.opentelemetry.io/otel/codes" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" "go.opentelemetry.io/otel/trace" "github.com/rabbitmq/amqp091-go" @@ -19,9 +20,9 @@ type acknowledger struct { func (a *acknowledger) Ack(tag uint64, multiple bool) error { err := a.acker.Ack(tag, multiple) if multiple { - a.endMultiple(tag, codes.Ok, "", err) + a.endMultiple(tag, codes.Ok, "ack", err) } else { - a.endOne(tag, codes.Ok, "", err) + a.endOne(tag, codes.Ok, "ack", err) } return err } @@ -47,6 +48,7 @@ func (a *acknowledger) endMultiple(lastTag uint64, code codes.Code, desc string, defer a.ch.m.Unlock() for tag, span := range a.ch.spanMap { + span.SetAttributes(semconv.MessagingOperationName(desc)) if tag <= lastTag { if err != nil { span.RecordError(err) @@ -62,6 +64,7 @@ func (a *acknowledger) endOne(tag uint64, code codes.Code, desc string, err erro a.ch.m.Lock() defer a.ch.m.Unlock() + a.span.SetAttributes(semconv.MessagingOperationName(desc)) if err != nil { a.span.RecordError(err) } diff --git a/channel.go b/channel.go index 0761fae..ef76112 100644 --- a/channel.go +++ b/channel.go @@ -7,7 +7,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - semconv "go.opentelemetry.io/otel/semconv/v1.25.0" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" "go.opentelemetry.io/otel/trace" "github.com/rabbitmq/amqp091-go" @@ -15,7 +15,6 @@ import ( const ( netProtocolVer = "0.9.1" - messageSystem = "rabbitmq" ) func queueAnonymous(queue string) bool { @@ -87,12 +86,11 @@ func (ch *Channel) startConsumerSpan(msg *amqp091.Delivery, queue string, operat attrs := []attribute.KeyValue{ operation, semconv.MessagingDestinationAnonymous(queueAnonymous(queue)), - // fixme messaging.destination.name MUST be set to the name of the exchange. semconv.MessagingDestinationName(queue), semconv.MessagingDestinationPublishAnonymous(msg.Exchange == ""), semconv.MessagingDestinationPublishName(msg.Exchange), + // todo messaging.client.id semconv.MessagingRabbitmqDestinationRoutingKey(msg.RoutingKey), - // todo messaging.client_id } if msg.MessageCount != 0 { attrs = append(attrs, semconv.MessagingBatchMessageCount(int(msg.MessageCount))) @@ -136,7 +134,7 @@ func (ch *Channel) Consume( newDeliveries := make(chan amqp091.Delivery) go func() { for msg := range deliveries { - ch.startConsumerSpan(&msg, queue, semconv.MessagingOperationDeliver) + ch.startConsumerSpan(&msg, queue, semconv.MessagingOperationTypeDeliver) newDeliveries <- msg } close(newDeliveries) @@ -156,11 +154,12 @@ func (ch *Channel) PublishWithDeferredConfirmWithContext( ) (*amqp091.DeferredConfirmation, error) { // Create a span. attrs := []attribute.KeyValue{ - semconv.MessagingOperationPublish, + semconv.MessagingOperationTypePublish, + semconv.MessagingOperationName("send"), semconv.MessagingDestinationAnonymous(exchange == ""), semconv.MessagingDestinationName(exchange), + // todo messaging.client.id semconv.MessagingRabbitmqDestinationRoutingKey(key), - // todo messaging.client_id } if msg.CorrelationId != "" { attrs = append(attrs, semconv.MessagingMessageConversationID(msg.CorrelationId)) @@ -194,6 +193,6 @@ func (ch *Channel) Get(queue string, autoAck bool) (msg amqp091.Delivery, ok boo if err != nil || !ok { return } - ch.startConsumerSpan(&msg, queue, semconv.MessagingOperationReceive) + ch.startConsumerSpan(&msg, queue, semconv.MessagingOperationTypeReceive) return msg, ok, err }