- 
                Notifications
    You must be signed in to change notification settings 
- Fork 147
Closed
Labels
Description
Hello,
recently it was announced that:
AWS X-Ray integrates with Amazon Simple Queue Service (Amazon SQS) to trace messages that are passed through an Amazon SQS queue.
What I fail to get is a nice map as shown here : https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html
Specifically the arrow between SQS and custom sqs poller.
I have : API GW->LAMBDA->SQS->Custom python script with instrumented aws xray sdk that polls sqs
In the Lambda I have the following code:
...
        trace_entity = xray_recorder.get_trace_entity()
        trace_header = TraceHeader(root=trace_entity.trace_id, parent=trace_entity.id,
                                   sampled=trace_entity.sampled)
        message['MessageSystemAttributes'] = {
            'AWSTraceHeader': {
                'StringValue': trace_header.to_header_str(),
                'DataType': 'String'
            }
        }
        sqs_client.send_message(**message)and in the sqs poller :
def _yielded_receive(self) -> List[SQSMessage]:
        return self.sqs.receive_messages(MessageAttributeNames=['All'],
                                             AttributeNames=['All'],
                                             VisibilityTimeout=self.VisibilityTimeout,
                                             WaitTimeSeconds=self.WaitTimeSeconds,
                                             MaxNumberOfMessages=self.MaxNumberOfMessages)
for raw_sqs_message in self._yielded_receive():
    trace_header = 
    TraceHeader.from_header_str(raw_sqs_message.attributes.get('AWSTraceHeader'))
    trace_id = trace_header.root
    sampled = trace_header.sampled
    segment = xray_recorder.begin_segment('SQS Receive',
                                                              traceid=trace_id,
                                                              sampling=sampled,
                                                              parent_id=trace_header.parent)And with this I get in the x-ray map : API GW -> Lambda -> SQS Poller ; and SQS tied to Lambda separately.
xrn, Sam-Martin and szbartnikxrn

