Skip to content

Commit afdbca0

Browse files
committed
refactor old spanattrs to new
1 parent e2ba6d4 commit afdbca0

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@
4343
unwrap,
4444
)
4545
from opentelemetry.propagators.textmap import CarrierT, Getter, Setter
46+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
47+
MESSAGING_CONVERSATION_ID,
48+
MESSAGING_DESTINATION,
49+
MESSAGING_DESTINATION_KIND,
50+
MESSAGING_MESSAGE_ID,
51+
MESSAGING_OPERATION,
52+
MESSAGING_SYSTEM,
53+
MESSAGING_URL,
54+
)
4655
from opentelemetry.semconv.trace import (
4756
MessagingDestinationKindValues,
4857
MessagingOperationValues,
49-
SpanAttributes,
5058
)
5159
from opentelemetry.trace import Link, Span, SpanKind, Tracer, TracerProvider
5260

@@ -151,24 +159,20 @@ def _enrich_span(
151159
) -> None:
152160
if not span.is_recording():
153161
return
154-
span.set_attribute(SpanAttributes.MESSAGING_SYSTEM, "aws.sqs")
155-
span.set_attribute(SpanAttributes.MESSAGING_DESTINATION, queue_name)
162+
span.set_attribute(MESSAGING_SYSTEM, "aws.sqs")
163+
span.set_attribute(MESSAGING_DESTINATION, queue_name)
156164
span.set_attribute(
157-
SpanAttributes.MESSAGING_DESTINATION_KIND,
165+
MESSAGING_DESTINATION_KIND,
158166
MessagingDestinationKindValues.QUEUE.value,
159167
)
160-
span.set_attribute(SpanAttributes.MESSAGING_URL, queue_url)
168+
span.set_attribute(MESSAGING_URL, queue_url)
161169

162170
if operation:
163-
span.set_attribute(
164-
SpanAttributes.MESSAGING_OPERATION, operation.value
165-
)
171+
span.set_attribute(MESSAGING_OPERATION, operation.value)
166172
if conversation_id:
167-
span.set_attribute(
168-
SpanAttributes.MESSAGING_CONVERSATION_ID, conversation_id
169-
)
173+
span.set_attribute(MESSAGING_CONVERSATION_ID, conversation_id)
170174
if message_id:
171-
span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message_id)
175+
span.set_attribute(MESSAGING_MESSAGE_ID, message_id)
172176

173177
@staticmethod
174178
def _safe_end_processing_span(receipt_handle: str) -> None:
@@ -239,9 +243,7 @@ def send_wrapper(wrapped, instance, args, kwargs):
239243
message_id = retval.get("MessageId")
240244
if message_id:
241245
if span.is_recording():
242-
span.set_attribute(
243-
SpanAttributes.MESSAGING_MESSAGE_ID, message_id
244-
)
246+
span.set_attribute(MESSAGING_MESSAGE_ID, message_id)
245247
return retval
246248

247249
wrap_function_wrapper(sqs_class, "send_message", send_wrapper)
@@ -284,7 +286,7 @@ def send_batch_wrapper(wrapped, instance, args, kwargs):
284286
if message_span:
285287
if message_span.is_recording():
286288
message_span.set_attribute(
287-
SpanAttributes.MESSAGING_MESSAGE_ID,
289+
MESSAGING_MESSAGE_ID,
288290
successful_messages.get("MessageId"),
289291
)
290292
for span in ids_to_spans.values():

instrumentation/opentelemetry-instrumentation-boto3sqs/tests/test_boto3sqs_instrumentation.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@
2727
Boto3SQSInstrumentor,
2828
Boto3SQSSetter,
2929
)
30+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
31+
MESSAGING_DESTINATION,
32+
MESSAGING_DESTINATION_KIND,
33+
MESSAGING_MESSAGE_ID,
34+
MESSAGING_OPERATION,
35+
MESSAGING_SYSTEM,
36+
MESSAGING_URL,
37+
)
3038
from opentelemetry.semconv.trace import (
3139
MessagingDestinationKindValues,
3240
MessagingOperationValues,
33-
SpanAttributes,
3441
)
3542
from opentelemetry.test.test_base import TestBase
3643
from opentelemetry.trace import SpanKind
@@ -223,10 +230,10 @@ def _assert_injected_span(self, msg_attrs: Dict[str, Any], span: Span):
223230

224231
def _default_span_attrs(self):
225232
return {
226-
SpanAttributes.MESSAGING_SYSTEM: "aws.sqs",
227-
SpanAttributes.MESSAGING_DESTINATION: self._queue_name,
228-
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
229-
SpanAttributes.MESSAGING_URL: self._queue_url,
233+
MESSAGING_SYSTEM: "aws.sqs",
234+
MESSAGING_DESTINATION: self._queue_name,
235+
MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
236+
MESSAGING_URL: self._queue_url,
230237
}
231238

232239
@staticmethod
@@ -282,7 +289,7 @@ def test_send_message(self):
282289
self.assertEqual(SpanKind.PRODUCER, span.kind)
283290
self.assertEqual(
284291
{
285-
SpanAttributes.MESSAGING_MESSAGE_ID: message_id,
292+
MESSAGING_MESSAGE_ID: message_id,
286293
**self._default_span_attrs(),
287294
},
288295
span.attributes,
@@ -321,7 +328,7 @@ def test_receive_message(self):
321328
self.assertEqual(SpanKind.CONSUMER, span.kind)
322329
self.assertEqual(
323330
{
324-
SpanAttributes.MESSAGING_OPERATION: MessagingOperationValues.RECEIVE.value,
331+
MESSAGING_OPERATION: MessagingOperationValues.RECEIVE.value,
325332
**self._default_span_attrs(),
326333
},
327334
span.attributes,
@@ -345,8 +352,8 @@ def test_receive_message(self):
345352
# processing span attributes
346353
self.assertEqual(
347354
{
348-
SpanAttributes.MESSAGING_MESSAGE_ID: msg_id,
349-
SpanAttributes.MESSAGING_OPERATION: MessagingOperationValues.PROCESS.value,
355+
MESSAGING_MESSAGE_ID: msg_id,
356+
MESSAGING_OPERATION: MessagingOperationValues.PROCESS.value,
350357
**self._default_span_attrs(),
351358
},
352359
span.attributes,

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy-wrapt]
2+
ignore_missing_imports = True

0 commit comments

Comments
 (0)