-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lamda handler Context does not contain Segment #126
Comments
context.Context
does not contain Segment
Hi underscorenygren, The issue here is, there is no segment to get. In Lambda, the segment is created (and emitted) on behalf of the Lambda runtime start-up code. The SDK uses the header as derived from the Lambda context to create a facade segment (and an underlying basic segment): aws-xray-sdk-go/xray/segment.go Lines 45 to 52 in 3565e35
aws-xray-sdk-go/xray/segment.go Line 102 in 3565e35
This facade segment acts as a placeholder, such that the SDK can stream subsegments without additional special code to handle this Lambda case. But, this does not exist on the ctx object until a subsegment is created. The facade is created as needed when a new subsegment is created: aws-xray-sdk-go/xray/segment.go Lines 153 to 161 in 73cfeb4
Thus, any GetSegment will always return nil when outside of a created subsegment. In the Node SDK we emit a warning saying this is unsupported: But, you should be able to see the facade segment after the construction of the subsegment: Hopefully this helps, let us know your thoughts. Is there a better way we can address this situation? |
Hi Sandra, I found the BeginFacadeSegment by trawling through the source, but the reference you refer to is a bit obscure, and the Another example below lambda showcasing the use of straight xray without the |
Yes, admittedly, it's not super clear you do not need to worry about the segment on the examples, or the readme for that matter. We have had the question a few times on the Node issues. We'd be happy to review anything you'd like to submit. Thanks! |
@underscorenygren Updated our Go SDK README to better explain the Lambda use case. Feel free to open issues if you have questions in future. |
The comment here seems to suggest we do the following:
However, this implementation inside of my lambda does not associate a traceID to the subsegment and all my logs are no longer associated with the trace this execution is tied to. The alternative is we create a segment inside of our lambda and that way all of our logs get associated with the trace. But this causes Xray to treat the lambda execution as separate from the root trace because it creates a brand new trace. What is the correct way to introduce tracing to my lambda and have all my logs be tied to it and be able to extract a traceID to put inside of my log messages? I can't find any documentation on this |
Bug
When an APIGateway enabled lambda function with tracing information passes it's context to
xray.TraceID()
it does not return the trace id from the header. This leads to downstream issues for tracing sinceGetSegment
is always nil.Expected Result
xray.TraceID
should return the same trace ID that's present in the header.Reproduce
tried on
v1.0.0rc-12
The following handler illustrates the problem, the output should return the same trace ids.
The text was updated successfully, but these errors were encountered: