aws x-ray with python

Viewed 377

This is my Python code with AWS X-Ray

There is no Error but it is not sending anything to X-Ray Daemon.

What is missing in this code ?

from aws_xray_sdk.core import xray_recorder


xray_recorder.configure(daemon_address="xx.xx.xx.xx:2000")
# Start a segment
segment = xray_recorder.begin_segment('segment_name')
# Start a subsegment
subsegment = xray_recorder.begin_subsegment('subsegment_name')

# Add metadata and annotations
segment.put_metadata('key', dict, 'namespace')
subsegment.put_annotation('key', 'value')

# Close the subsegment and segment
xray_recorder.end_subsegment()
xray_recorder.end_segment()```
1 Answers

Do you have the prerequisites in place to use x-ray? This means:

  1. Make sure the lambda has permissions to send to x-ray. Lambda needs the following permissions to send trace data to X-Ray. Add them to your function's execution role.
    • xray:PutTraceSegments
    • xray:PutTelemetryRecords

These permissions are included in the AWSXRayDaemonWriteAccess managed policy.

  1. Recommended: enable active tracing on your lambda. This sends data to x-ray out of the box and enables some useful troubleshooting capabilities like lambda cold start times.

More info in the aws docs

Related