fix(logger): add xray_trace_id to every log #776
Merged
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_id
key 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_ID
environment 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_id
key when the log entry is created and populated instead (createAndPopulateLogItem
function). This behaviour is consistent with the implementation also used in the Python version of Powertools.As additional notes:
packages/logger/tests/helpers/populateEnvironmentVariables.ts
which is imported before tests are run. So when running the tests thexray_trace_id
would always be present._X_AMZN_TRACE_ID
environment 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.