Skip to content

How to make X-Ray traces clickable from CloudWatch logs insights? #5741

Discussion options

You must be logged in to vote

Hey @softwareengineerprogrammer! If you want that CW Logs Dashboard render the TracerId with a link to Tracer, then you need to log the field X-Amzn-Trace-Id as part of your log line. In this way CW will detect this field and render this as @xRayTracerId. With Powertools you have some ways to do that.

1 - Adding this as an extra key. You must take care to get _X_AMZN_TRACE_ID from the env, it changes on every Lambda run and it doesn't matter if this is a new container or not, so put this inside the Lambda handler.

import os
from aws_lambda_powertools import Logger

logger = Logger()

def lambda_handler(event: dict, context: LambdaContext) -> str:
	mylog = {
	    "X-Amzn-Trace-Id": os.getenv(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@softwareengineerprogrammer
Comment options

Answer selected by softwareengineerprogrammer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants