23
23
24
24
_SUPPORTED_OPERATIONS = ["SendMessage" , "SendMessageBatch" , "ReceiveMessage" ]
25
25
26
+ logger = logging .getLogger (__name__ )
27
+
26
28
27
29
class _SqsExtension (_AwsSdkExtension ):
28
30
def extract_attributes (self , attributes : _AttributeMapT ):
@@ -32,25 +34,36 @@ def extract_attributes(self, attributes: _AttributeMapT):
32
34
attributes ["aws.queue_url" ] = queue_url
33
35
attributes [SpanAttributes .MESSAGING_SYSTEM ] = "aws.sqs"
34
36
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
+ )
38
46
39
47
def on_success (self , span : Span , result : _BotoResultT ):
40
48
operation = self ._call_context .operation
41
49
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" )
0 commit comments