From f31d77787691b79603b018b8dc7c38ac8b3baa04 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Thu, 3 Jul 2025 21:48:58 -0300 Subject: [PATCH 1/8] feat: refactor semcov opentelemetry-instrumentation --- .../opentelemetry/instrumentation/_semconv.py | 104 ++++++++++-------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py index f3f3fb6201..8d2f4d36c5 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py @@ -17,6 +17,24 @@ from enum import Enum from opentelemetry.instrumentation.utils import http_status_to_status_code +from opentelemetry.semconv._incubating.attributes.http_attributes import ( + HTTP_FLAVOR, + HTTP_HOST, + HTTP_METHOD, + HTTP_SCHEME, + HTTP_SERVER_NAME, + HTTP_STATUS_CODE, + HTTP_TARGET, + HTTP_URL, + HTTP_USER_AGENT, +) +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_HOST_NAME, + NET_HOST_PORT, + NET_PEER_IP, + NET_PEER_NAME, + NET_PEER_PORT, +) from opentelemetry.semconv.attributes.client_attributes import ( CLIENT_ADDRESS, CLIENT_PORT, @@ -44,7 +62,7 @@ from opentelemetry.semconv.attributes.user_agent_attributes import ( USER_AGENT_ORIGINAL, ) -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv.schemas import Schemas from opentelemetry.trace.status import Status, StatusCode # Values defined in milliseconds @@ -87,13 +105,13 @@ # These lists represent attributes for metrics that are currently supported _client_duration_attrs_old = [ - SpanAttributes.HTTP_STATUS_CODE, - SpanAttributes.HTTP_HOST, - SpanAttributes.NET_PEER_PORT, - SpanAttributes.NET_PEER_NAME, - SpanAttributes.HTTP_METHOD, - SpanAttributes.HTTP_FLAVOR, - SpanAttributes.HTTP_SCHEME, + HTTP_STATUS_CODE, + HTTP_HOST, + HTTP_METHOD, + HTTP_FLAVOR, + HTTP_SCHEME, + NET_PEER_PORT, + NET_PEER_NAME, ] _client_duration_attrs_new = [ @@ -108,14 +126,14 @@ ] _server_duration_attrs_old = [ - SpanAttributes.HTTP_METHOD, - SpanAttributes.HTTP_HOST, - SpanAttributes.HTTP_SCHEME, - SpanAttributes.HTTP_STATUS_CODE, - SpanAttributes.HTTP_FLAVOR, - SpanAttributes.HTTP_SERVER_NAME, - SpanAttributes.NET_HOST_NAME, - SpanAttributes.NET_HOST_PORT, + HTTP_METHOD, + HTTP_HOST, + HTTP_SCHEME, + HTTP_STATUS_CODE, + HTTP_FLAVOR, + HTTP_SERVER_NAME, + NET_HOST_NAME, + NET_HOST_PORT, ] _server_duration_attrs_new = [ @@ -128,11 +146,11 @@ ] _server_active_requests_count_attrs_old = [ - SpanAttributes.HTTP_METHOD, - SpanAttributes.HTTP_HOST, - SpanAttributes.HTTP_SCHEME, - SpanAttributes.HTTP_FLAVOR, - SpanAttributes.HTTP_SERVER_NAME, + HTTP_METHOD, + HTTP_HOST, + HTTP_SCHEME, + HTTP_FLAVOR, + HTTP_SERVER_NAME, ] _server_active_requests_count_attrs_new = [ @@ -287,44 +305,42 @@ def _set_http_method(result, original, normalized, sem_conv_opt_in_mode): set_string_attribute(result, HTTP_REQUEST_METHOD_ORIGINAL, original) if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_METHOD, normalized) + set_string_attribute(result, HTTP_METHOD, normalized) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, HTTP_REQUEST_METHOD, normalized) def _set_http_status_code(result, code, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, SpanAttributes.HTTP_STATUS_CODE, code) + set_int_attribute(result, HTTP_STATUS_CODE, code) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, HTTP_RESPONSE_STATUS_CODE, code) def _set_http_url(result, url, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_URL, url) + set_string_attribute(result, HTTP_URL, url) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, URL_FULL, url) def _set_http_scheme(result, scheme, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_SCHEME, scheme) + set_string_attribute(result, HTTP_SCHEME, scheme) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, URL_SCHEME, scheme) def _set_http_flavor_version(result, version, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_FLAVOR, version) + set_string_attribute(result, HTTP_FLAVOR, version) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, NETWORK_PROTOCOL_VERSION, version) def _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute( - result, SpanAttributes.HTTP_USER_AGENT, user_agent - ) + set_string_attribute(result, HTTP_USER_AGENT, user_agent) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, USER_AGENT_ORIGINAL, user_agent) @@ -334,28 +350,28 @@ def _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode): def _set_http_host_client(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_HOST, host) + set_string_attribute(result, HTTP_HOST, host) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, host) def _set_http_net_peer_name_client(result, peer_name, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.NET_PEER_NAME, peer_name) + set_string_attribute(result, NET_PEER_NAME, peer_name) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, peer_name) def _set_http_peer_port_client(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, SpanAttributes.NET_PEER_PORT, port) + set_int_attribute(result, NET_PEER_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, SERVER_PORT, port) def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_FLAVOR, version) + set_string_attribute(result, HTTP_FLAVOR, version) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, NETWORK_PROTOCOL_VERSION, version) @@ -365,21 +381,21 @@ def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode): def _set_http_net_host(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.NET_HOST_NAME, host) + set_string_attribute(result, NET_HOST_NAME, host) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, host) def _set_http_net_host_port(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, SpanAttributes.NET_HOST_PORT, port) + set_int_attribute(result, NET_HOST_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, SERVER_PORT, port) def _set_http_target(result, target, path, query, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_TARGET, target) + set_string_attribute(result, HTTP_TARGET, target) if _report_new(sem_conv_opt_in_mode): if path: set_string_attribute(result, URL_PATH, path) @@ -389,7 +405,7 @@ def _set_http_target(result, target, path, query, sem_conv_opt_in_mode): def _set_http_host_server(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.HTTP_HOST, host) + set_string_attribute(result, HTTP_HOST, host) if _report_new(sem_conv_opt_in_mode): if not result.get(SERVER_ADDRESS): set_string_attribute(result, SERVER_ADDRESS, host) @@ -402,7 +418,7 @@ def _set_http_host_server(result, host, sem_conv_opt_in_mode): # https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#common-attributes-across-http-client-and-server-spans def _set_http_peer_ip_server(result, ip, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.NET_PEER_IP, ip) + set_string_attribute(result, NET_PEER_IP, ip) if _report_new(sem_conv_opt_in_mode): # Only populate if not already populated if not result.get(CLIENT_ADDRESS): @@ -411,14 +427,14 @@ def _set_http_peer_ip_server(result, ip, sem_conv_opt_in_mode): def _set_http_peer_port_server(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, SpanAttributes.NET_PEER_PORT, port) + set_int_attribute(result, NET_PEER_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, CLIENT_PORT, port) def _set_http_net_peer_name_server(result, name, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, SpanAttributes.NET_PEER_NAME, name) + set_string_attribute(result, NET_PEER_NAME, name) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, CLIENT_ADDRESS, name) @@ -450,10 +466,8 @@ def _set_status( if _report_old(sem_conv_opt_in_mode): if span.is_recording(): - span.set_attribute( - SpanAttributes.HTTP_STATUS_CODE, status_code - ) - metrics_attributes[SpanAttributes.HTTP_STATUS_CODE] = status_code + span.set_attribute(HTTP_STATUS_CODE, status_code) + metrics_attributes[HTTP_STATUS_CODE] = status_code if _report_new(sem_conv_opt_in_mode): if span.is_recording(): span.set_attribute(HTTP_RESPONSE_STATUS_CODE, status_code) @@ -470,4 +484,4 @@ def _set_status( def _get_schema_url(mode: _StabilityMode) -> str: if mode is _StabilityMode.DEFAULT: return "https://opentelemetry.io/schemas/1.11.0" - return SpanAttributes.SCHEMA_URL + return Schemas.V1_33_0.value From 97a1e3dbcb663fbc0aa403c6779a708ac47d1ca1 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Fri, 11 Jul 2025 07:20:31 -0300 Subject: [PATCH 2/8] fix: return shema senconv --- .../src/opentelemetry/instrumentation/_semconv.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py index 8d2f4d36c5..80794246c0 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py @@ -62,7 +62,6 @@ from opentelemetry.semconv.attributes.user_agent_attributes import ( USER_AGENT_ORIGINAL, ) -from opentelemetry.semconv.schemas import Schemas from opentelemetry.trace.status import Status, StatusCode # Values defined in milliseconds @@ -484,4 +483,4 @@ def _set_status( def _get_schema_url(mode: _StabilityMode) -> str: if mode is _StabilityMode.DEFAULT: return "https://opentelemetry.io/schemas/1.11.0" - return Schemas.V1_33_0.value + return "https://opentelemetry.io/schemas/1.21.0" From cff86f4046c2b603c525af2284ce371cf624fd02 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Thu, 31 Jul 2025 19:40:42 -0300 Subject: [PATCH 3/8] refactor: opentelemetry-instrumentation-aio-pika --- .../instrumentation/aio_pika/span_builder.py | 33 +++++++++------ .../tests/consts.py | 2 +- .../tests/test_callback_decorator.py | 42 ++++++++++++------- .../tests/test_publish_decorator.py | 42 ++++++++++++------- 4 files changed, 73 insertions(+), 46 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py index dd5433756c..2890dcd946 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py @@ -16,13 +16,24 @@ from aio_pika.abc import AbstractChannel, AbstractMessage from opentelemetry.instrumentation.utils import is_instrumentation_enabled +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( + MESSAGING_DESTINATION_NAME, + MESSAGING_DESTINATION_TEMPORARY, + MESSAGING_MESSAGE_CONVERSATION_ID, + MESSAGING_MESSAGE_ID, + MESSAGING_OPERATION, + MESSAGING_SYSTEM, +) +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_NAME, + NET_PEER_PORT, +) from opentelemetry.semconv.trace import ( MessagingOperationValues, - SpanAttributes, ) from opentelemetry.trace import Span, SpanKind, Tracer -_DEFAULT_ATTRIBUTES = {SpanAttributes.MESSAGING_SYSTEM: "rabbitmq"} +_DEFAULT_ATTRIBUTES = {MESSAGING_SYSTEM: "rabbitmq"} class SpanBuilder: @@ -44,7 +55,7 @@ def set_operation(self, operation: MessagingOperationValues): def set_destination(self, destination: str): self._destination = destination - self._attributes[SpanAttributes.MESSAGING_DESTINATION] = destination + self._attributes[MESSAGING_DESTINATION_NAME] = destination def set_channel(self, channel: AbstractChannel): if hasattr(channel, "_connection"): @@ -61,19 +72,17 @@ def set_channel(self, channel: AbstractChannel): url = connection.url self._attributes.update( { - SpanAttributes.NET_PEER_NAME: url.host, - SpanAttributes.NET_PEER_PORT: url.port or 5672, + NET_PEER_NAME: url.host, + NET_PEER_PORT: url.port or 5672, } ) def set_message(self, message: AbstractMessage): properties = message.properties if properties.message_id: - self._attributes[SpanAttributes.MESSAGING_MESSAGE_ID] = ( - properties.message_id - ) + self._attributes[MESSAGING_MESSAGE_ID] = properties.message_id if properties.correlation_id: - self._attributes[SpanAttributes.MESSAGING_CONVERSATION_ID] = ( + self._attributes[MESSAGING_MESSAGE_CONVERSATION_ID] = ( properties.correlation_id ) @@ -81,11 +90,9 @@ def build(self) -> Optional[Span]: if not is_instrumentation_enabled(): return None if self._operation: - self._attributes[SpanAttributes.MESSAGING_OPERATION] = ( - self._operation.value - ) + self._attributes[MESSAGING_OPERATION] = self._operation.value else: - self._attributes[SpanAttributes.MESSAGING_TEMP_DESTINATION] = True + self._attributes[MESSAGING_DESTINATION_TEMPORARY] = True span = self._tracer.start_span( self._generate_span_name(), kind=self._kind, diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/consts.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/consts.py index 431780ae7b..9be41cc844 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/consts.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/consts.py @@ -6,7 +6,7 @@ AIOPIKA_VERSION_INFO = tuple(int(v) for v in aiopika_version.split(".")) MESSAGE_ID = "meesage_id" CORRELATION_ID = "correlation_id" -MESSAGING_SYSTEM = "rabbitmq" +MESSAGING_SYSTEM_VALUE = "rabbitmq" EXCHANGE_NAME = "exchange_name" QUEUE_NAME = "queue_name" ROUTING_KEY = "routing_key" diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py index 39a7724bfa..bd6a70137b 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py @@ -19,7 +19,17 @@ from opentelemetry.instrumentation.aio_pika.callback_decorator import ( CallbackDecorator, ) -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( + MESSAGING_DESTINATION_NAME, + MESSAGING_MESSAGE_CONVERSATION_ID, + MESSAGING_MESSAGE_ID, + MESSAGING_OPERATION, + MESSAGING_SYSTEM, +) +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_NAME, + NET_PEER_PORT, +) from opentelemetry.trace import SpanKind, get_tracer from .consts import ( @@ -30,7 +40,7 @@ EXCHANGE_NAME, MESSAGE, MESSAGE_ID, - MESSAGING_SYSTEM, + MESSAGING_SYSTEM_VALUE, QUEUE_NAME, SERVER_HOST, SERVER_PORT, @@ -40,13 +50,13 @@ @skipIf(AIOPIKA_VERSION_INFO >= (8, 0), "Only for aio_pika 7") class TestInstrumentedQueueAioRmq7(TestCase): EXPECTED_ATTRIBUTES = { - SpanAttributes.MESSAGING_SYSTEM: MESSAGING_SYSTEM, - SpanAttributes.MESSAGING_DESTINATION: EXCHANGE_NAME, - SpanAttributes.NET_PEER_NAME: SERVER_HOST, - SpanAttributes.NET_PEER_PORT: SERVER_PORT, - SpanAttributes.MESSAGING_MESSAGE_ID: MESSAGE_ID, - SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, - SpanAttributes.MESSAGING_OPERATION: "receive", + MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, + MESSAGING_DESTINATION_NAME: EXCHANGE_NAME, + NET_PEER_NAME: SERVER_HOST, + NET_PEER_PORT: SERVER_PORT, + MESSAGING_MESSAGE_ID: MESSAGE_ID, + MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + MESSAGING_OPERATION: "receive", } def setUp(self): @@ -80,13 +90,13 @@ def test_decorate_callback(self): @skipIf(AIOPIKA_VERSION_INFO <= (8, 0), "Only for aio_pika 8") class TestInstrumentedQueueAioRmq8(TestCase): EXPECTED_ATTRIBUTES = { - SpanAttributes.MESSAGING_SYSTEM: MESSAGING_SYSTEM, - SpanAttributes.MESSAGING_DESTINATION: EXCHANGE_NAME, - SpanAttributes.NET_PEER_NAME: SERVER_HOST, - SpanAttributes.NET_PEER_PORT: SERVER_PORT, - SpanAttributes.MESSAGING_MESSAGE_ID: MESSAGE_ID, - SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, - SpanAttributes.MESSAGING_OPERATION: "receive", + MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, + MESSAGING_DESTINATION_NAME: EXCHANGE_NAME, + NET_PEER_NAME: SERVER_HOST, + NET_PEER_PORT: SERVER_PORT, + MESSAGING_MESSAGE_ID: MESSAGE_ID, + MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + MESSAGING_OPERATION: "receive", } def setUp(self): diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py index 90a029531d..b5272d4dfb 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py @@ -21,7 +21,17 @@ from opentelemetry.instrumentation.aio_pika.publish_decorator import ( PublishDecorator, ) -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( + MESSAGING_DESTINATION_NAME, + MESSAGING_DESTINATION_TEMPORARY, + MESSAGING_MESSAGE_CONVERSATION_ID, + MESSAGING_MESSAGE_ID, + MESSAGING_SYSTEM, +) +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_PEER_NAME, + NET_PEER_PORT, +) from opentelemetry.trace import SpanKind, get_tracer from .consts import ( @@ -34,7 +44,7 @@ EXCHANGE_NAME, MESSAGE, MESSAGE_ID, - MESSAGING_SYSTEM, + MESSAGING_SYSTEM_VALUE, ROUTING_KEY, SERVER_HOST, SERVER_PORT, @@ -44,13 +54,13 @@ @skipIf(AIOPIKA_VERSION_INFO >= (8, 0), "Only for aio_pika 7") class TestInstrumentedExchangeAioRmq7(TestCase): EXPECTED_ATTRIBUTES = { - SpanAttributes.MESSAGING_SYSTEM: MESSAGING_SYSTEM, - SpanAttributes.MESSAGING_DESTINATION: f"{EXCHANGE_NAME},{ROUTING_KEY}", - SpanAttributes.NET_PEER_NAME: SERVER_HOST, - SpanAttributes.NET_PEER_PORT: SERVER_PORT, - SpanAttributes.MESSAGING_MESSAGE_ID: MESSAGE_ID, - SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, - SpanAttributes.MESSAGING_TEMP_DESTINATION: True, + MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, + MESSAGING_DESTINATION_NAME: f"{EXCHANGE_NAME},{ROUTING_KEY}", + NET_PEER_NAME: SERVER_HOST, + NET_PEER_PORT: SERVER_PORT, + MESSAGING_MESSAGE_ID: MESSAGE_ID, + MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + MESSAGING_DESTINATION_TEMPORARY: True, } def setUp(self): @@ -123,13 +133,13 @@ def test_publish_works_with_not_recording_span_robust(self): @skipIf(AIOPIKA_VERSION_INFO <= (8, 0), "Only for aio_pika 8") class TestInstrumentedExchangeAioRmq8(TestCase): EXPECTED_ATTRIBUTES = { - SpanAttributes.MESSAGING_SYSTEM: MESSAGING_SYSTEM, - SpanAttributes.MESSAGING_DESTINATION: f"{EXCHANGE_NAME},{ROUTING_KEY}", - SpanAttributes.NET_PEER_NAME: SERVER_HOST, - SpanAttributes.NET_PEER_PORT: SERVER_PORT, - SpanAttributes.MESSAGING_MESSAGE_ID: MESSAGE_ID, - SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, - SpanAttributes.MESSAGING_TEMP_DESTINATION: True, + MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, + MESSAGING_DESTINATION_NAME: f"{EXCHANGE_NAME},{ROUTING_KEY}", + NET_PEER_NAME: SERVER_HOST, + NET_PEER_PORT: SERVER_PORT, + MESSAGING_MESSAGE_ID: MESSAGE_ID, + MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + MESSAGING_DESTINATION_TEMPORARY: True, } def setUp(self): From a754cff10dbd5f77b83d3a1e95edb0db4a93762a Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Thu, 31 Jul 2025 19:46:19 -0300 Subject: [PATCH 4/8] fix: revert unintended changes to _semconv.py --- .../opentelemetry/instrumentation/_semconv.py | 103 ++++++++---------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py index 80794246c0..f3f3fb6201 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py @@ -17,24 +17,6 @@ from enum import Enum from opentelemetry.instrumentation.utils import http_status_to_status_code -from opentelemetry.semconv._incubating.attributes.http_attributes import ( - HTTP_FLAVOR, - HTTP_HOST, - HTTP_METHOD, - HTTP_SCHEME, - HTTP_SERVER_NAME, - HTTP_STATUS_CODE, - HTTP_TARGET, - HTTP_URL, - HTTP_USER_AGENT, -) -from opentelemetry.semconv._incubating.attributes.net_attributes import ( - NET_HOST_NAME, - NET_HOST_PORT, - NET_PEER_IP, - NET_PEER_NAME, - NET_PEER_PORT, -) from opentelemetry.semconv.attributes.client_attributes import ( CLIENT_ADDRESS, CLIENT_PORT, @@ -62,6 +44,7 @@ from opentelemetry.semconv.attributes.user_agent_attributes import ( USER_AGENT_ORIGINAL, ) +from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.status import Status, StatusCode # Values defined in milliseconds @@ -104,13 +87,13 @@ # These lists represent attributes for metrics that are currently supported _client_duration_attrs_old = [ - HTTP_STATUS_CODE, - HTTP_HOST, - HTTP_METHOD, - HTTP_FLAVOR, - HTTP_SCHEME, - NET_PEER_PORT, - NET_PEER_NAME, + SpanAttributes.HTTP_STATUS_CODE, + SpanAttributes.HTTP_HOST, + SpanAttributes.NET_PEER_PORT, + SpanAttributes.NET_PEER_NAME, + SpanAttributes.HTTP_METHOD, + SpanAttributes.HTTP_FLAVOR, + SpanAttributes.HTTP_SCHEME, ] _client_duration_attrs_new = [ @@ -125,14 +108,14 @@ ] _server_duration_attrs_old = [ - HTTP_METHOD, - HTTP_HOST, - HTTP_SCHEME, - HTTP_STATUS_CODE, - HTTP_FLAVOR, - HTTP_SERVER_NAME, - NET_HOST_NAME, - NET_HOST_PORT, + SpanAttributes.HTTP_METHOD, + SpanAttributes.HTTP_HOST, + SpanAttributes.HTTP_SCHEME, + SpanAttributes.HTTP_STATUS_CODE, + SpanAttributes.HTTP_FLAVOR, + SpanAttributes.HTTP_SERVER_NAME, + SpanAttributes.NET_HOST_NAME, + SpanAttributes.NET_HOST_PORT, ] _server_duration_attrs_new = [ @@ -145,11 +128,11 @@ ] _server_active_requests_count_attrs_old = [ - HTTP_METHOD, - HTTP_HOST, - HTTP_SCHEME, - HTTP_FLAVOR, - HTTP_SERVER_NAME, + SpanAttributes.HTTP_METHOD, + SpanAttributes.HTTP_HOST, + SpanAttributes.HTTP_SCHEME, + SpanAttributes.HTTP_FLAVOR, + SpanAttributes.HTTP_SERVER_NAME, ] _server_active_requests_count_attrs_new = [ @@ -304,42 +287,44 @@ def _set_http_method(result, original, normalized, sem_conv_opt_in_mode): set_string_attribute(result, HTTP_REQUEST_METHOD_ORIGINAL, original) if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_METHOD, normalized) + set_string_attribute(result, SpanAttributes.HTTP_METHOD, normalized) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, HTTP_REQUEST_METHOD, normalized) def _set_http_status_code(result, code, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, HTTP_STATUS_CODE, code) + set_int_attribute(result, SpanAttributes.HTTP_STATUS_CODE, code) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, HTTP_RESPONSE_STATUS_CODE, code) def _set_http_url(result, url, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_URL, url) + set_string_attribute(result, SpanAttributes.HTTP_URL, url) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, URL_FULL, url) def _set_http_scheme(result, scheme, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_SCHEME, scheme) + set_string_attribute(result, SpanAttributes.HTTP_SCHEME, scheme) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, URL_SCHEME, scheme) def _set_http_flavor_version(result, version, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_FLAVOR, version) + set_string_attribute(result, SpanAttributes.HTTP_FLAVOR, version) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, NETWORK_PROTOCOL_VERSION, version) def _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_USER_AGENT, user_agent) + set_string_attribute( + result, SpanAttributes.HTTP_USER_AGENT, user_agent + ) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, USER_AGENT_ORIGINAL, user_agent) @@ -349,28 +334,28 @@ def _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode): def _set_http_host_client(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_HOST, host) + set_string_attribute(result, SpanAttributes.HTTP_HOST, host) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, host) def _set_http_net_peer_name_client(result, peer_name, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, NET_PEER_NAME, peer_name) + set_string_attribute(result, SpanAttributes.NET_PEER_NAME, peer_name) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, peer_name) def _set_http_peer_port_client(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, NET_PEER_PORT, port) + set_int_attribute(result, SpanAttributes.NET_PEER_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, SERVER_PORT, port) def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_FLAVOR, version) + set_string_attribute(result, SpanAttributes.HTTP_FLAVOR, version) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, NETWORK_PROTOCOL_VERSION, version) @@ -380,21 +365,21 @@ def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode): def _set_http_net_host(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, NET_HOST_NAME, host) + set_string_attribute(result, SpanAttributes.NET_HOST_NAME, host) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, SERVER_ADDRESS, host) def _set_http_net_host_port(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, NET_HOST_PORT, port) + set_int_attribute(result, SpanAttributes.NET_HOST_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, SERVER_PORT, port) def _set_http_target(result, target, path, query, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_TARGET, target) + set_string_attribute(result, SpanAttributes.HTTP_TARGET, target) if _report_new(sem_conv_opt_in_mode): if path: set_string_attribute(result, URL_PATH, path) @@ -404,7 +389,7 @@ def _set_http_target(result, target, path, query, sem_conv_opt_in_mode): def _set_http_host_server(result, host, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, HTTP_HOST, host) + set_string_attribute(result, SpanAttributes.HTTP_HOST, host) if _report_new(sem_conv_opt_in_mode): if not result.get(SERVER_ADDRESS): set_string_attribute(result, SERVER_ADDRESS, host) @@ -417,7 +402,7 @@ def _set_http_host_server(result, host, sem_conv_opt_in_mode): # https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#common-attributes-across-http-client-and-server-spans def _set_http_peer_ip_server(result, ip, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, NET_PEER_IP, ip) + set_string_attribute(result, SpanAttributes.NET_PEER_IP, ip) if _report_new(sem_conv_opt_in_mode): # Only populate if not already populated if not result.get(CLIENT_ADDRESS): @@ -426,14 +411,14 @@ def _set_http_peer_ip_server(result, ip, sem_conv_opt_in_mode): def _set_http_peer_port_server(result, port, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_int_attribute(result, NET_PEER_PORT, port) + set_int_attribute(result, SpanAttributes.NET_PEER_PORT, port) if _report_new(sem_conv_opt_in_mode): set_int_attribute(result, CLIENT_PORT, port) def _set_http_net_peer_name_server(result, name, sem_conv_opt_in_mode): if _report_old(sem_conv_opt_in_mode): - set_string_attribute(result, NET_PEER_NAME, name) + set_string_attribute(result, SpanAttributes.NET_PEER_NAME, name) if _report_new(sem_conv_opt_in_mode): set_string_attribute(result, CLIENT_ADDRESS, name) @@ -465,8 +450,10 @@ def _set_status( if _report_old(sem_conv_opt_in_mode): if span.is_recording(): - span.set_attribute(HTTP_STATUS_CODE, status_code) - metrics_attributes[HTTP_STATUS_CODE] = status_code + span.set_attribute( + SpanAttributes.HTTP_STATUS_CODE, status_code + ) + metrics_attributes[SpanAttributes.HTTP_STATUS_CODE] = status_code if _report_new(sem_conv_opt_in_mode): if span.is_recording(): span.set_attribute(HTTP_RESPONSE_STATUS_CODE, status_code) @@ -483,4 +470,4 @@ def _set_status( def _get_schema_url(mode: _StabilityMode) -> str: if mode is _StabilityMode.DEFAULT: return "https://opentelemetry.io/schemas/1.11.0" - return "https://opentelemetry.io/schemas/1.21.0" + return SpanAttributes.SCHEMA_URL From a38dd2c818e270ba9bc1a5643372ef1ccf950df5 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Tue, 5 Aug 2025 18:49:05 -0300 Subject: [PATCH 5/8] fix: change schema --- .../opentelemetry/instrumentation/aio_pika/span_builder.py | 6 ++++-- .../tests/test_callback_decorator.py | 6 +++--- .../tests/test_publish_decorator.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py index 2890dcd946..494184ab23 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py @@ -17,7 +17,6 @@ from opentelemetry.instrumentation.utils import is_instrumentation_enabled from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_DESTINATION_NAME, MESSAGING_DESTINATION_TEMPORARY, MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, @@ -30,6 +29,7 @@ ) from opentelemetry.semconv.trace import ( MessagingOperationValues, + SpanAttributes, ) from opentelemetry.trace import Span, SpanKind, Tracer @@ -55,7 +55,9 @@ def set_operation(self, operation: MessagingOperationValues): def set_destination(self, destination: str): self._destination = destination - self._attributes[MESSAGING_DESTINATION_NAME] = destination + # TODO: Update this implementation once the semantic conventions for messaging stabilize + # See: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/messaging.md + self._attributes[SpanAttributes.MESSAGING_DESTINATION] = destination def set_channel(self, channel: AbstractChannel): if hasattr(channel, "_connection"): diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py index bd6a70137b..ef0bcf6482 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py @@ -20,7 +20,6 @@ CallbackDecorator, ) from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_DESTINATION_NAME, MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_OPERATION, @@ -30,6 +29,7 @@ NET_PEER_NAME, NET_PEER_PORT, ) +from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, get_tracer from .consts import ( @@ -51,7 +51,7 @@ class TestInstrumentedQueueAioRmq7(TestCase): EXPECTED_ATTRIBUTES = { MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, - MESSAGING_DESTINATION_NAME: EXCHANGE_NAME, + SpanAttributes.MESSAGING_DESTINATION: EXCHANGE_NAME, NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, @@ -91,7 +91,7 @@ def test_decorate_callback(self): class TestInstrumentedQueueAioRmq8(TestCase): EXPECTED_ATTRIBUTES = { MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, - MESSAGING_DESTINATION_NAME: EXCHANGE_NAME, + SpanAttributes.MESSAGING_DESTINATION: EXCHANGE_NAME, NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py index b5272d4dfb..59a2767176 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py @@ -22,7 +22,6 @@ PublishDecorator, ) from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_DESTINATION_NAME, MESSAGING_DESTINATION_TEMPORARY, MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, @@ -32,6 +31,7 @@ NET_PEER_NAME, NET_PEER_PORT, ) +from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, get_tracer from .consts import ( @@ -55,7 +55,7 @@ class TestInstrumentedExchangeAioRmq7(TestCase): EXPECTED_ATTRIBUTES = { MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, - MESSAGING_DESTINATION_NAME: f"{EXCHANGE_NAME},{ROUTING_KEY}", + SpanAttributes.MESSAGING_DESTINATION: f"{EXCHANGE_NAME},{ROUTING_KEY}", NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, @@ -134,7 +134,7 @@ def test_publish_works_with_not_recording_span_robust(self): class TestInstrumentedExchangeAioRmq8(TestCase): EXPECTED_ATTRIBUTES = { MESSAGING_SYSTEM: MESSAGING_SYSTEM_VALUE, - MESSAGING_DESTINATION_NAME: f"{EXCHANGE_NAME},{ROUTING_KEY}", + SpanAttributes.MESSAGING_DESTINATION: f"{EXCHANGE_NAME},{ROUTING_KEY}", NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, From 59bc13984e029b8e61c898f11ef77766d67f0af3 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Tue, 5 Aug 2025 19:08:09 -0300 Subject: [PATCH 6/8] fix: change schema --- .../opentelemetry/instrumentation/aio_pika/span_builder.py | 5 +++-- .../tests/test_publish_decorator.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py index 494184ab23..71cd9300e5 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py @@ -17,7 +17,6 @@ from opentelemetry.instrumentation.utils import is_instrumentation_enabled from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_DESTINATION_TEMPORARY, MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_OPERATION, @@ -94,7 +93,9 @@ def build(self) -> Optional[Span]: if self._operation: self._attributes[MESSAGING_OPERATION] = self._operation.value else: - self._attributes[MESSAGING_DESTINATION_TEMPORARY] = True + # TODO: Update this implementation once the semantic conventions for messaging stabilize + # See: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/messaging.md + self._attributes[SpanAttributes.MESSAGING_TEMP_DESTINATION] = True span = self._tracer.start_span( self._generate_span_name(), kind=self._kind, diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py index 59a2767176..d4aa047ef4 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py @@ -22,7 +22,6 @@ PublishDecorator, ) from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_DESTINATION_TEMPORARY, MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_SYSTEM, @@ -60,7 +59,7 @@ class TestInstrumentedExchangeAioRmq7(TestCase): NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, - MESSAGING_DESTINATION_TEMPORARY: True, + SpanAttributes.MESSAGING_TEMP_DESTINATION: True, } def setUp(self): @@ -139,7 +138,7 @@ class TestInstrumentedExchangeAioRmq8(TestCase): NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, - MESSAGING_DESTINATION_TEMPORARY: True, + SpanAttributes.MESSAGING_TEMP_DESTINATION: True, } def setUp(self): From 65dc5431fae503fbd17ff8a1d0b996c7e79774ef Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Tue, 2 Sep 2025 07:03:07 -0300 Subject: [PATCH 7/8] fix: spanattribute messaging id --- .../src/opentelemetry/instrumentation/aio_pika/span_builder.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py index 71cd9300e5..9fd25747e7 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py @@ -17,7 +17,6 @@ from opentelemetry.instrumentation.utils import is_instrumentation_enabled from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_OPERATION, MESSAGING_SYSTEM, @@ -83,7 +82,7 @@ def set_message(self, message: AbstractMessage): if properties.message_id: self._attributes[MESSAGING_MESSAGE_ID] = properties.message_id if properties.correlation_id: - self._attributes[MESSAGING_MESSAGE_CONVERSATION_ID] = ( + self._attributes[SpanAttributes.MESSAGING_CONVERSATION_ID] = ( properties.correlation_id ) From 391951074c4f13192221dd9e9c48ca2a6a9b74b7 Mon Sep 17 00:00:00 2001 From: Ezzio Moreira Date: Tue, 2 Sep 2025 07:12:34 -0300 Subject: [PATCH 8/8] fix: spanattribute messaging id --- .../tests/test_callback_decorator.py | 5 ++--- .../tests/test_publish_decorator.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py index ef0bcf6482..8b54c384de 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_callback_decorator.py @@ -20,7 +20,6 @@ CallbackDecorator, ) from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_OPERATION, MESSAGING_SYSTEM, @@ -55,7 +54,7 @@ class TestInstrumentedQueueAioRmq7(TestCase): NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, - MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, MESSAGING_OPERATION: "receive", } @@ -95,7 +94,7 @@ class TestInstrumentedQueueAioRmq8(TestCase): NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, - MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, MESSAGING_OPERATION: "receive", } diff --git a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py index d4aa047ef4..da5bdb1ad5 100644 --- a/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py +++ b/instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py @@ -22,7 +22,6 @@ PublishDecorator, ) from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( - MESSAGING_MESSAGE_CONVERSATION_ID, MESSAGING_MESSAGE_ID, MESSAGING_SYSTEM, ) @@ -58,7 +57,7 @@ class TestInstrumentedExchangeAioRmq7(TestCase): NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, - MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, SpanAttributes.MESSAGING_TEMP_DESTINATION: True, } @@ -137,7 +136,7 @@ class TestInstrumentedExchangeAioRmq8(TestCase): NET_PEER_NAME: SERVER_HOST, NET_PEER_PORT: SERVER_PORT, MESSAGING_MESSAGE_ID: MESSAGE_ID, - MESSAGING_MESSAGE_CONVERSATION_ID: CORRELATION_ID, + SpanAttributes.MESSAGING_CONVERSATION_ID: CORRELATION_ID, SpanAttributes.MESSAGING_TEMP_DESTINATION: True, }