Tracer: How do I pass in parent trace IDs from SQS AWSTraceHeader? #1235
-
I have an xray enabled Lambda function (using the Tracer module) sending messages to a queue, and a function consuming messages from that queue. This function is also xray enabled with the Tracer module. I understand that I need to manually recover this trace context ID to keep the xray service map for my process connected (https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html#xray-services-sqs-retrieving). That said, I am failing to see a way to set this parent ID anywhere via the Tracer module or even by escape hatching to a context manager. Has anyone solved this issue, or know the inner workings of the escape hatch and the raw xray sdk well enough to give recommendation? Thank you in advance! # sample of consuming function code
...
from aws_lambda_powertools import Logger, Metrics, Tracer
from aws_lambda_powertools.metrics import MetricUnit
from aws_lambda_powertools.utilities.parser import parse, BaseModel, validator
from aws_lambda_powertools.utilities.parser.models import SqsModel, SqsRecordModel
...
@logger.inject_lambda_context(log_event=True)
@metrics.log_metrics
@tracer.capture_lambda_handler
def lambda_handler(event: SqsModel, context):
for record in event.Records:
record: MySqlRecord = parse(event=record, model=MySqlRecord)
record.attributes.AWSTraceHeader
# what do? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Seems like even using the xray sdk directly it is still not working cleanly : |
Beta Was this translation helpful? Give feedback.
-
The AWS X-Ray team is working on that, please email your AWS Account representatives to add your company +1. Background: AWS Lambda service creates an immutable root segment (segment). When your function is executed, you won't be able to mutate to course correct the trace as the original documentation suggests - that is only possible when you're not using Lambda. Because multiple SQS messages might contain different traces, it is not a trivial problem for them to solve as the Lambda being invoked may not be connected to their respective parent segment. Once this is solved by the AWS X-Ray team we should see it automatically resolved in both Lambda Powertools, AWS X-Ray SDK, and any other tracing library that rely on the AWS X-Ray service. Hope that helps. |
Beta Was this translation helpful? Give feedback.
The AWS X-Ray team is working on that, please email your AWS Account representatives to add your company +1.
Background: AWS Lambda service creates an immutable root segment (segment). When your function is executed, you won't be able to mutate to course correct the trace as the original documentation suggests - that is only possible when you're not using Lambda. Because multiple SQS messages might contain different traces, it is not a trivial problem for them to solve as the Lambda being invoked may not be connected to their respective parent segment.
Once this is solved by the AWS X-Ray team we should see it automatically resolved in both Lambda Powertools, AWS X-Ray SDK, and any other …