Skip to content

Commit fa39299

Browse files
committed
refactor: don't use deprecated SpanAttributes in kafka
1 parent 4a1e0ce commit fa39299

File tree

1 file changed

+15
-18
lines changed
  • instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka

1 file changed

+15
-18
lines changed

instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
from opentelemetry import context, propagate
55
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,
1014
)
1115
from opentelemetry.trace import Link, SpanKind
1216

@@ -114,32 +118,25 @@ def _enrich_span(
114118
topic,
115119
partition: Optional[int] = None,
116120
offset: Optional[int] = None,
117-
operation: Optional[MessagingOperationValues] = None,
121+
operation: Optional[MessagingOperationTypeValues] = None,
118122
):
119123
if not span.is_recording():
120124
return
121125

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)
125128
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)
133130
if operation:
134-
span.set_attribute(SpanAttributes.MESSAGING_OPERATION, operation.value)
131+
span.set_attribute(MESSAGING_OPERATION, operation.value)
135132
else:
136-
span.set_attribute(SpanAttributes.MESSAGING_TEMP_DESTINATION, True)
133+
span.set_attribute(MESSAGING_DESTINATION_TEMPORARY, True)
137134

138135
# https://stackoverflow.com/questions/65935155/identify-and-find-specific-message-in-kafka-topic
139136
# A message within Kafka is uniquely defined by its topic name, topic partition and offset.
140137
if partition is not None and offset is not None and topic:
141138
span.set_attribute(
142-
SpanAttributes.MESSAGING_MESSAGE_ID,
139+
MESSAGING_MESSAGE_ID,
143140
f"{topic}.{partition}.{offset}",
144141
)
145142

0 commit comments

Comments
 (0)