fix(logger): add xray_trace_id to every log - #776
Merged
dreamorosi merged 4 commits intoApr 29, 2022
Conversation
Contributor
Author
|
See e2e test result here (passing): https://github.com/awslabs/aws-lambda-powertools-typescript/runs/6041778790?check_suite_focus=true |
ijemmy
reviewed
Apr 20, 2022
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
ijemmy
approved these changes
Apr 26, 2022
flochaz
approved these changes
Apr 29, 2022
dreamorosi
deleted the
773-bug-logger-xray_trace_id-is-not-populated-in-log-lines
branch
April 29, 2022 08:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
As reported by user @humanzz in #773 the Logger utility was not including the
xray_trace_idkey in logs. This field is listed in the documentation as a standard key that should appear in each log.The user reporting the issue was helpful in detailing the fact that the
_X_AMZN_TRACE_IDenvironment variable used to retrieve the value changes at every invocation while Logger was instead attempting to read this value when instantiated (seeconstructor->setOptions->setPowertoolLogData).This PR changes this behaviour and appends the
xray_trace_idkey when the log entry is created and populated instead (createAndPopulateLogItemfunction). This behaviour is consistent with the implementation also used in the Python version of Powertools.As additional notes:
packages/logger/tests/helpers/populateEnvironmentVariables.tswhich is imported before tests are run. So when running the tests thexray_trace_idwould always be present._X_AMZN_TRACE_IDenvironment variable is always set in the Lambda execution environment, regardless of whether tracing is enabled or not. This means the key will always be present in each log. AWS Lambda Powertools for Python makes the same statement and I have tested the latest version available of the library on a Lambda function with Active Tracing disabled and the key is also always present in each log.How to verify this change
Related issues, RFCs
#773
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.