Skip to content

Commit 63bc931

Browse files
author
CircleCI
committed
fix srikanthccv's CR
1 parent 7c07598 commit 63bc931

File tree

2 files changed

+32
-19
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore

2 files changed

+32
-19
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sqs.py

+31-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
_SUPPORTED_OPERATIONS = ["SendMessage", "SendMessageBatch", "ReceiveMessage"]
2525

26+
logger = logging.getLogger(__name__)
27+
2628

2729
class _SqsExtension(_AwsSdkExtension):
2830
def extract_attributes(self, attributes: _AttributeMapT):
@@ -32,25 +34,36 @@ def extract_attributes(self, attributes: _AttributeMapT):
3234
attributes["aws.queue_url"] = queue_url
3335
attributes[SpanAttributes.MESSAGING_SYSTEM] = "aws.sqs"
3436
attributes[SpanAttributes.MESSAGING_URL] = queue_url
35-
attributes[SpanAttributes.MESSAGING_DESTINATION] = queue_url.split(
36-
"/"
37-
)[-1]
37+
try:
38+
attributes[
39+
SpanAttributes.MESSAGING_DESTINATION
40+
] = queue_url.split("/")[-1]
41+
except IndexError:
42+
logger.error(
43+
"Could not extract messaging destination from '%s'",
44+
queue_url,
45+
)
3846

3947
def on_success(self, span: Span, result: _BotoResultT):
4048
operation = self._call_context.operation
4149
if operation in _SUPPORTED_OPERATIONS:
42-
if operation == "SendMessage":
43-
span.set_attribute(
44-
SpanAttributes.MESSAGING_MESSAGE_ID,
45-
result.get("MessageId"),
46-
)
47-
elif operation == "SendMessageBatch" and result.get("Successful"):
48-
span.set_attribute(
49-
SpanAttributes.MESSAGING_MESSAGE_ID,
50-
result["Successful"][0]["MessageId"],
51-
)
52-
elif operation == "ReceiveMessage" and result.get("Messages"):
53-
span.set_attribute(
54-
SpanAttributes.MESSAGING_MESSAGE_ID,
55-
result["Messages"][0]["MessageId"],
56-
)
50+
try:
51+
if operation == "SendMessage":
52+
span.set_attribute(
53+
SpanAttributes.MESSAGING_MESSAGE_ID,
54+
result.get("MessageId"),
55+
)
56+
elif operation == "SendMessageBatch" and result.get(
57+
"Successful"
58+
):
59+
span.set_attribute(
60+
SpanAttributes.MESSAGING_MESSAGE_ID,
61+
result["Successful"][0]["MessageId"],
62+
)
63+
elif operation == "ReceiveMessage" and result.get("Messages"):
64+
span.set_attribute(
65+
SpanAttributes.MESSAGING_MESSAGE_ID,
66+
result["Messages"][0]["MessageId"],
67+
)
68+
except (IndexError, KeyError):
69+
logger.error("Could not extract the messaging message if")

Diff for: instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sqs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from opentelemetry.test.test_base import TestBase
77

88

9-
class TestDynamoDbExtension(TestBase):
9+
class TestSqsExtension(TestBase):
1010
def setUp(self):
1111
super().setUp()
1212
BotocoreInstrumentor().instrument()

0 commit comments

Comments
 (0)