|
3 | 3 |
|
4 | 4 | from opentelemetry import context, propagate
|
5 | 5 | from opentelemetry.propagators import textmap
|
6 |
| -from opentelemetry.semconv.trace import ( |
7 |
| - MessagingDestinationKindValues, |
8 |
| - MessagingOperationValues, |
9 |
| - SpanAttributes, |
| 6 | +from opentelemetry.semconv._incubating.attributes.messaging_attributes import ( |
| 7 | + MESSAGING_DESTINATION_NAME, |
| 8 | + MESSAGING_DESTINATION_TEMPORARY, |
| 9 | + MESSAGING_KAFKA_DESTINATION_PARTITION, |
| 10 | + MESSAGING_MESSAGE_ID, |
| 11 | + MESSAGING_OPERATION, |
| 12 | + MESSAGING_SYSTEM, |
| 13 | + MessagingOperationTypeValues, |
10 | 14 | )
|
11 | 15 | from opentelemetry.trace import Link, SpanKind
|
12 | 16 |
|
@@ -114,32 +118,25 @@ def _enrich_span(
|
114 | 118 | topic,
|
115 | 119 | partition: Optional[int] = None,
|
116 | 120 | offset: Optional[int] = None,
|
117 |
| - operation: Optional[MessagingOperationValues] = None, |
| 121 | + operation: Optional[MessagingOperationTypeValues] = None, |
118 | 122 | ):
|
119 | 123 | if not span.is_recording():
|
120 | 124 | return
|
121 | 125 |
|
122 |
| - span.set_attribute(SpanAttributes.MESSAGING_SYSTEM, "kafka") |
123 |
| - span.set_attribute(SpanAttributes.MESSAGING_DESTINATION, topic) |
124 |
| - |
| 126 | + span.set_attribute(MESSAGING_SYSTEM, "kafka") |
| 127 | + span.set_attribute(MESSAGING_DESTINATION_NAME, topic) |
125 | 128 | if partition is not None:
|
126 |
| - span.set_attribute(SpanAttributes.MESSAGING_KAFKA_PARTITION, partition) |
127 |
| - |
128 |
| - span.set_attribute( |
129 |
| - SpanAttributes.MESSAGING_DESTINATION_KIND, |
130 |
| - MessagingDestinationKindValues.QUEUE.value, |
131 |
| - ) |
132 |
| - |
| 129 | + span.set_attribute(MESSAGING_KAFKA_DESTINATION_PARTITION, partition) |
133 | 130 | if operation:
|
134 |
| - span.set_attribute(SpanAttributes.MESSAGING_OPERATION, operation.value) |
| 131 | + span.set_attribute(MESSAGING_OPERATION, operation.value) |
135 | 132 | else:
|
136 |
| - span.set_attribute(SpanAttributes.MESSAGING_TEMP_DESTINATION, True) |
| 133 | + span.set_attribute(MESSAGING_DESTINATION_TEMPORARY, True) |
137 | 134 |
|
138 | 135 | # https://stackoverflow.com/questions/65935155/identify-and-find-specific-message-in-kafka-topic
|
139 | 136 | # A message within Kafka is uniquely defined by its topic name, topic partition and offset.
|
140 | 137 | if partition is not None and offset is not None and topic:
|
141 | 138 | span.set_attribute(
|
142 |
| - SpanAttributes.MESSAGING_MESSAGE_ID, |
| 139 | + MESSAGING_MESSAGE_ID, |
143 | 140 | f"{topic}.{partition}.{offset}",
|
144 | 141 | )
|
145 | 142 |
|
|
0 commit comments