diff --git a/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py b/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py index 83e5ed70bc..187c150f3c 100644 --- a/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py @@ -43,10 +43,16 @@ unwrap, ) from opentelemetry.propagators.textmap import CarrierT, Getter, Setter -from opentelemetry.semconv.trace import ( - MessagingDestinationKindValues, - MessagingOperationValues, - SpanAttributes, +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( + MESSAGING_DESTINATION_NAME, + MESSAGING_MESSAGE_CONVERSATION_ID, + MESSAGING_MESSAGE_ID, + MESSAGING_OPERATION, + MESSAGING_SYSTEM, + MessagingOperationTypeValues, +) +from opentelemetry.semconv.attributes.server_attributes import ( + SERVER_ADDRESS, ) from opentelemetry.trace import Link, Span, SpanKind, Tracer, TracerProvider @@ -146,29 +152,23 @@ def _enrich_span( queue_name: str, queue_url: str, conversation_id: Optional[str] = None, - operation: Optional[MessagingOperationValues] = None, + operation: Optional[MessagingOperationTypeValues] = None, message_id: Optional[str] = None, ) -> None: if not span.is_recording(): return - span.set_attribute(SpanAttributes.MESSAGING_SYSTEM, "aws.sqs") - span.set_attribute(SpanAttributes.MESSAGING_DESTINATION, queue_name) - span.set_attribute( - SpanAttributes.MESSAGING_DESTINATION_KIND, - MessagingDestinationKindValues.QUEUE.value, - ) - span.set_attribute(SpanAttributes.MESSAGING_URL, queue_url) + span.set_attribute(MESSAGING_SYSTEM, "aws.sqs") + span.set_attribute(MESSAGING_DESTINATION_NAME, queue_name) + span.set_attribute(SERVER_ADDRESS, queue_url) if operation: - span.set_attribute( - SpanAttributes.MESSAGING_OPERATION, operation.value - ) + span.set_attribute(MESSAGING_OPERATION, operation.value) if conversation_id: span.set_attribute( - SpanAttributes.MESSAGING_CONVERSATION_ID, conversation_id + MESSAGING_MESSAGE_CONVERSATION_ID, conversation_id ) if message_id: - span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message_id) + span.set_attribute(MESSAGING_MESSAGE_ID, message_id) @staticmethod def _safe_end_processing_span(receipt_handle: str) -> None: @@ -214,7 +214,7 @@ def _create_processing_span( queue_name, queue_url, message_id=message_id, - operation=MessagingOperationValues.PROCESS, + operation=MessagingOperationTypeValues.PROCESS, ) def _wrap_send_message(self, sqs_class: type) -> None: @@ -239,9 +239,7 @@ def send_wrapper(wrapped, instance, args, kwargs): message_id = retval.get("MessageId") if message_id: if span.is_recording(): - span.set_attribute( - SpanAttributes.MESSAGING_MESSAGE_ID, message_id - ) + span.set_attribute(MESSAGING_MESSAGE_ID, message_id) return retval wrap_function_wrapper(sqs_class, "send_message", send_wrapper) @@ -284,7 +282,7 @@ def send_batch_wrapper(wrapped, instance, args, kwargs): if message_span: if message_span.is_recording(): message_span.set_attribute( - SpanAttributes.MESSAGING_MESSAGE_ID, + MESSAGING_MESSAGE_ID, successful_messages.get("MessageId"), ) for span in ids_to_spans.values(): @@ -314,7 +312,7 @@ def receive_message_wrapper(wrapped, instance, args, kwargs): span, queue_name, queue_url, - operation=MessagingOperationValues.RECEIVE, + operation=MessagingOperationTypeValues.RECEIVE, ) retval = wrapped( *args, diff --git a/instrumentation/opentelemetry-instrumentation-boto3sqs/tests/test_boto3sqs_instrumentation.py b/instrumentation/opentelemetry-instrumentation-boto3sqs/tests/test_boto3sqs_instrumentation.py index 7f7f00cf0a..1db2c1000c 100644 --- a/instrumentation/opentelemetry-instrumentation-boto3sqs/tests/test_boto3sqs_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-boto3sqs/tests/test_boto3sqs_instrumentation.py @@ -27,10 +27,15 @@ Boto3SQSInstrumentor, Boto3SQSSetter, ) -from opentelemetry.semconv.trace import ( - MessagingDestinationKindValues, - MessagingOperationValues, - SpanAttributes, +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( + MESSAGING_DESTINATION_NAME, + MESSAGING_MESSAGE_ID, + MESSAGING_OPERATION, + MESSAGING_SYSTEM, + MessagingOperationTypeValues, +) +from opentelemetry.semconv.attributes.server_attributes import ( + SERVER_ADDRESS, ) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind @@ -223,10 +228,9 @@ def _assert_injected_span(self, msg_attrs: Dict[str, Any], span: Span): def _default_span_attrs(self): return { - SpanAttributes.MESSAGING_SYSTEM: "aws.sqs", - SpanAttributes.MESSAGING_DESTINATION: self._queue_name, - SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value, - SpanAttributes.MESSAGING_URL: self._queue_url, + MESSAGING_SYSTEM: "aws.sqs", + MESSAGING_DESTINATION_NAME: self._queue_name, + SERVER_ADDRESS: self._queue_url, } @staticmethod @@ -282,7 +286,7 @@ def test_send_message(self): self.assertEqual(SpanKind.PRODUCER, span.kind) self.assertEqual( { - SpanAttributes.MESSAGING_MESSAGE_ID: message_id, + MESSAGING_MESSAGE_ID: message_id, **self._default_span_attrs(), }, span.attributes, @@ -321,7 +325,7 @@ def test_receive_message(self): self.assertEqual(SpanKind.CONSUMER, span.kind) self.assertEqual( { - SpanAttributes.MESSAGING_OPERATION: MessagingOperationValues.RECEIVE.value, + MESSAGING_OPERATION: MessagingOperationTypeValues.RECEIVE.value, **self._default_span_attrs(), }, span.attributes, @@ -345,8 +349,8 @@ def test_receive_message(self): # processing span attributes self.assertEqual( { - SpanAttributes.MESSAGING_MESSAGE_ID: msg_id, - SpanAttributes.MESSAGING_OPERATION: MessagingOperationValues.PROCESS.value, + MESSAGING_MESSAGE_ID: msg_id, + MESSAGING_OPERATION: MessagingOperationTypeValues.PROCESS.value, **self._default_span_attrs(), }, span.attributes,