-
Notifications
You must be signed in to change notification settings - Fork 403
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
Include X-Ray Trace ID in Logger when detected #137
Comments
Thanks for raising the issue @brysontyrrell :) We definitely want to do this. I have one question for you, though: At what point should this key be added?
|
@brysontyrrell could you double check the implementation meets your expectation? We'll only add the key |
@heitorlessa Sorry for the delay in replying! I took a look at the implementation you linked. The trace ID changes for each invocation. Setting in the init of the formatter would mean that the logger would have to be initialized in the handler and not the root, right? |
That is absolutely true, and I completely forgot that! @brysontyrrell - This means we'll only guarantee this if customers use the Does that still work for you? |
@heitorlessa That would still work. I'd like to know more about how the Python Lambda environment configures the root logger to handle this as it sets the trace ID in the logger for each invoke even if you've initialized in the global context. Example output from some testing I just did:
The logger parsed this from the env var (not the segment ID though - unsure where's that set so the logger can discover it):
|
This is likely at the |
Perf impact is negligible, this change won't impact customers - Difference in fetching it while formatting log records is ~0.10 nanoseconds. I'll change this now, and merge the PR after updating tests :) -- It'll be in the next release during this coming week Thanks again for the heads up @brysontyrrell |
I've just tested it and works @brysontyrrell, also worked with the Service Lens team to ensure this will work consistently :) Merging soon, and will update here once it's released along with other new shiny features in 1.5.0 this week |
feat: add xray_trace_id key when tracing is active #137
Closing as this was included in 1.5.0 :) |
Is your feature request related to a problem? Please describe.
When using CloudWatch ServiceLens, logs are aggregated if the lines contain the trace ID you're looking at. This is handled by the default root logger, but it lost when using the Powertools logger.
The Powertools logger would be more powerful is it worked better together with both X-Ray and ServiceLens. Structured JSON logging is must easier to search and view in ServiceLens results. The whole thing becomes a better out-of-the-box solution.
Describe the solution you'd like
If present, I would like the X-Ray trace ID appended automatically to the log structure.
Describe alternatives you've considered
I've worked around this in one Lambda Function I've been using to try out Powertools.
The text was updated successfully, but these errors were encountered: