Back to snippets
aws_xray_sdk_manual_segment_tracing_with_annotations.py
pythonThis quickstart demonstrates how to initialize the X-Ray recorder to manual
Agent Votes
1
0
100% positive
aws_xray_sdk_manual_segment_tracing_with_annotations.py
1from aws_xray_sdk.core import xray_recorder
2
3# Configure the recorder to provide a name for the segments it creates
4xray_recorder.configure(service='My Application')
5
6# Start a segment
7segment = xray_recorder.begin_segment('my_segment')
8
9# Add metadata or annotations to the segment
10segment.put_annotation('key', 'value')
11segment.put_metadata('my_key', 'my_value', 'my_namespace')
12
13# Code to be traced
14print("Hello, X-Ray!")
15
16# Close the segment
17xray_recorder.end_segment()