Skip to content

Commit 828e7f1

Browse files
author
CircleCI
committed
fix srikanthccv's CR
1 parent 6d76c83 commit 828e7f1

File tree

2 files changed

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

2 files changed

+33
-19
lines changed

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

+32-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import logging
1415

1516
from opentelemetry.instrumentation.botocore.extensions.types import (
1617
_AttributeMapT,
@@ -22,6 +23,8 @@
2223

2324
_SUPPORTED_OPERATIONS = ["SendMessage", "SendMessageBatch", "ReceiveMessage"]
2425

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

2629
class _SqsExtension(_AwsSdkExtension):
2730
def extract_attributes(self, attributes: _AttributeMapT):
@@ -31,25 +34,36 @@ def extract_attributes(self, attributes: _AttributeMapT):
3134
attributes["aws.queue_url"] = queue_url
3235
attributes[SpanAttributes.MESSAGING_SYSTEM] = "aws.sqs"
3336
attributes[SpanAttributes.MESSAGING_URL] = queue_url
34-
attributes[SpanAttributes.MESSAGING_DESTINATION] = queue_url.split(
35-
"/"
36-
)[-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+
)
3746

3847
def on_success(self, span: Span, result: _BotoResultT):
3948
operation = self._call_context.operation
4049
if operation in _SUPPORTED_OPERATIONS:
41-
if operation == "SendMessage":
42-
span.set_attribute(
43-
SpanAttributes.MESSAGING_MESSAGE_ID,
44-
result.get("MessageId"),
45-
)
46-
elif operation == "SendMessageBatch" and result.get("Successful"):
47-
span.set_attribute(
48-
SpanAttributes.MESSAGING_MESSAGE_ID,
49-
result["Successful"][0]["MessageId"],
50-
)
51-
elif operation == "ReceiveMessage" and result.get("Messages"):
52-
span.set_attribute(
53-
SpanAttributes.MESSAGING_MESSAGE_ID,
54-
result["Messages"][0]["MessageId"],
55-
)
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)