feat(tracer): auto disable when running inside amplify mock #1010
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 discussed in #1007, the Amplify CLI allows developers to run Lambda functions locally during development. When not running inside the AWS Lambda execution environment the
xray-sdk
, and by extensionTracer
, will not be able to work properly as there isn't any X-Ray Daemon to connect to and send traces. Unless explicitly accounted for, the default behaviour of the SDK is to throw an exception.This is a problem as it requires developers using Tracer to make changes to their code only to be able to test locally. Similarly to what we already do with SAM CLI, in this PR I introduced some logic to leverage a special value set by the Amplify CLI in the environment variables (details here) to detect that Tracer is indeed running inside a process started by the Amplify CLI and automatically disable itself to avoid attempting to send traces and segments.
When merged this PR will close #1007.
How to verify this change
Check the newly added test cases as well as the result of the e2e tests (link in the comments below).
Related issues, RFCs
#1007
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.