2.4.0 X-Ray Subsegments Solved
Last updated
Last updated
Andrew's repo: week-2-xray-subsegments
My branch repo: 02-04-x-ray-subsegments-solved
On AWS X-Ray console, while the traces are coming through, but the specific service we are targeting (UserActivities) is not.
One of our fellow bootcamper Olga T. found the solution and shared the knowledge with us in her blog post. Andrew implements the suggested solution. The gist is that we did not close the X-Ray segments and subsegments. That is why X-Ray was unable to pick up the traces to send.
@xray_recorder.capture()
decorator in app.py
@xray_recorder.capture
: this decorator marks a particular function as a segment in the trace generated by AWS X-Ray.
So our data_handle()
function from the user_activities.py
service will be marked as a segment.
The following is an excerpt from the AWS documentation:
To create a subsegment for a synchronous function, use the @xray_recorder.capture
decorator. You can pass a name for the subsegment to the capture function or leave it out to use the function name.
As it was pointed out by Olga and Andrew, it is important to close the subsegments to ensure that X-Ray works correctly.
AWS: "To manage subsegments, use the begin_subsegment
and end_subsegment
methods."
After implementing the closure of the subsegments, the X-ray agent in the X-ray container correctly send the traces over to AWS.
In the image below, note that:
The segment created by the decorator @xray_recorder.capture("user-activities")
was recorded correctly.
The subsegment that was labeled in line 24 of the above code user_activities.py
also came through safely.