1

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()```
cofactor
  • 13
  • 6

1 Answers1

0

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

LRutten
  • 1,634
  • 7
  • 17
  • I am not using Lambda. I'm using this code in AWS Glue Job that is written in Python . There is no issue with permission either since I am using full xray:* permission. What is the possible cause that it is not writing to X-Ray ? Is there any code missing here ? – cofactor Sep 19 '21 at 18:00
  • Have you seen this post https://stackoverflow.com/questions/62594081/using-aws-x-ray-within-a-glue-python-shell-job? Does it help in any way? – LRutten Sep 19 '21 at 18:40
  • yes. I have seen that post. I already have AWS_XRAY_DAEMON_ADDRESS in the code and also in VM env variable and added x-ray SDK library in Glue and a VM spinned up to listen on 2000 port. My only hunch is , is my above Python code correct ? Is there anything I am missing ? do I require some code like xray_recorder.send() .....something like this ? // there is no send anyway, but you get the idea, – cofactor Sep 20 '21 at 05:31
  • To debug, you can add `import logging` to the top and add `logging.getLogger('aws_xray_sdk').setLevel(logging.DEBUG)` right after importing the x ray sdk. Maybe the logs help you further – LRutten Sep 20 '21 at 05:55