Skip to content

refactor (boto3sqs) spans #3542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@
unwrap,
)
from opentelemetry.propagators.textmap import CarrierT, Getter, Setter
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
MESSAGING_DESTINATION_NAME,
MESSAGING_MESSAGE_CONVERSATION_ID,
MESSAGING_MESSAGE_ID,
MESSAGING_OPERATION,
MESSAGING_SYSTEM,
)
from opentelemetry.semconv._incubating.attributes.server_attributes import (
SERVER_ADDRESS,
)
from opentelemetry.semconv.trace import (
MessagingDestinationKindValues,
MessagingOperationValues,
SpanAttributes,
)
from opentelemetry.trace import Link, Span, SpanKind, Tracer, TracerProvider

Expand Down Expand Up @@ -151,24 +159,18 @@ def _enrich_span(
) -> 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:
Expand Down Expand Up @@ -239,9 +241,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)
Expand Down Expand Up @@ -284,7 +284,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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
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,
)
from opentelemetry.semconv._incubating.attributes.server_attributes import (
SERVER_ADDRESS,
)
from opentelemetry.semconv.trace import MessagingOperationValues
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import SpanKind
from opentelemetry.trace.span import Span, format_span_id, format_trace_id
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: MessagingOperationValues.RECEIVE.value,
**self._default_span_attrs(),
},
span.attributes,
Expand All @@ -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: MessagingOperationValues.PROCESS.value,
**self._default_span_attrs(),
},
span.attributes,
Expand Down