open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
698 stars 579 forks source link

Make sure aio-pika instrumentation follows semantic conventions #1638

Open srikanthccv opened 1 year ago

P6rguVyrst commented 2 months ago

Would like to pick this up as part of: https://github.com/open-telemetry/opentelemetry-python/issues/4045

cc @xrmx

P6rguVyrst commented 2 months ago

In current version the required attributes for messaging-spans are:

Attribute Type Description Examples Requirement Level
messaging.operation.type string A string identifying the type of the messaging operation. [1] publish; create; receive Required
messaging.system string The messaging system as identified by the client instrumentation. [2] activemq; aws_sqs; eventgrid Required
error.type string Describes a class of error the operation ended with. [3] amqp:decode-error; KAFKA_STORAGE_ERROR; channel-error Conditionally Required If and only if the messaging operation has failed.
messaging.batch.message_count int The number of messages sent, received, or processed in the scope of the batching operation. [4] 0; 1; 2 Conditionally Required [5]
messaging.destination.anonymous boolean A boolean that is true if the message destination is anonymous (could be unnamed or have auto-generated name). Conditionally Required [6]
messaging.destination.name string The message destination name [7] MyQueue; MyTopic Conditionally Required [8]
messaging.destination.template string Low cardinality representation of the messaging destination name [9] /customers/{customerId} Conditionally Required [10]
messaging.destination.temporary boolean A boolean that is true if the message destination is temporary and might not exist anymore after messages are processed. Conditionally Required [11]
server.address string Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [12] example.com; 10.1.2.80; /tmp/my.sock Conditionally Required If available.

opentelemetry-instrumentation-aio-pika, is currently on the semconv version of 1.11.0, and we're looking to get to 1.26.0 (subject to change).

We use the following semantic convention classes to instrument the aio-pika library:

 from opentelemetry.semconv.trace import (                                                                                                     
     MessagingOperationValues,                                                                                                                 
     SpanAttributes,                                                                                                                           
 )

Within those we use the following 8 SpanAttributes:

SpanAttributes.MESSAGING_SYSTEM: "rabbitmq"
self._attributes[SpanAttributes.MESSAGING_DESTINATION] = destination
SpanAttributes.NET_PEER_NAME: url.host,
SpanAttributes.NET_PEER_PORT: url.port or 5672,
SpanAttributes.MESSAGING_MESSAGE_ID
SpanAttributes.MESSAGING_CONVERSATION_ID
self._attributes[SpanAttributes.MESSAGING_OPERATION] = self._operation.value
self._attributes[SpanAttributes.MESSAGING_TEMP_DESTINATION] = True

However, that location doesn't include the current semantic conventions, as they've been moved to semconv/_incubating/attributes

To follow the latest semantic conventions, we will need to reference the incubating values referenced above.