From ddab6034b3f1d6c419feec6cba25f3db92cb7a58 Mon Sep 17 00:00:00 2001 From: Nikita Pastukhov Date: Wed, 12 Jun 2024 21:44:54 +0300 Subject: [PATCH] fix: correct RabbitExchange processing by OTEL in broker.publish case --- faststream/rabbit/opentelemetry/provider.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/faststream/rabbit/opentelemetry/provider.py b/faststream/rabbit/opentelemetry/provider.py index 7ba8c1900e..6971810ff2 100644 --- a/faststream/rabbit/opentelemetry/provider.py +++ b/faststream/rabbit/opentelemetry/provider.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from opentelemetry.semconv.trace import SpanAttributes @@ -9,6 +9,7 @@ from aio_pika import IncomingMessage from faststream.broker.message import StreamMessage + from faststream.rabbit.schemas.exchange import RabbitExchange from faststream.types import AnyDict @@ -44,9 +45,12 @@ def get_publish_attrs_from_kwargs( self, kwargs: "AnyDict", ) -> "AnyDict": + exchange: Union[None, str, RabbitExchange] = kwargs.get("exchange") return { SpanAttributes.MESSAGING_SYSTEM: self.messaging_system, - SpanAttributes.MESSAGING_DESTINATION_NAME: kwargs.get("exchange") or "", + SpanAttributes.MESSAGING_DESTINATION_NAME: getattr( + exchange, "name", exchange or "" + ), SpanAttributes.MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY: kwargs[ "routing_key" ],