Skip to content
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

feat(tracer): auto disable when running inside amplify mock #1010

Merged
merged 2 commits into from
Jul 8, 2022

Conversation

dreamorosi
Copy link
Contributor

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 extension Tracer, 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

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • The PR title follows the conventional commit semantics

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.

@dreamorosi dreamorosi requested review from flochaz and saragerion June 28, 2022 11:30
@dreamorosi dreamorosi self-assigned this Jun 28, 2022
@@ -65,7 +65,7 @@ For a **complete list** of supported environment variables, refer to [this secti

#### Example using AWS Serverless Application Model (SAM)

The `Tracer` utility is instantiated outside of the Lambda handler. In doing this, the same instance can be used across multiple invocations inside the same execution environment. This allows `Metrics` to be aware of things like whether or not a given invocation had a cold start or not.
The `Tracer` utility is instantiated outside of the Lambda handler. In doing this, the same instance can be used across multiple invocations inside the same execution environment. This allows `Tracer` to be aware of things like whether or not a given invocation had a cold start or not.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Housekeeping

@github-actions
Copy link
Contributor

github-actions bot commented Jun 28, 2022

📊 Package size report   0.2%↑

File Before After
aws-lambda-powertools-tracer-0.11.1-rc.0.tgz 21.5 kB 0.4%↑21.5 kB
tracer-bundle.zip 22.0 kB 0.6%↑22.1 kB
Total (Includes all files) 140.7 kB 0.2%↑141.0 kB
Tarball size 139.6 kB 0.2%↑139.8 kB
Unchanged files
File Size
aws-lambda-powertools-commons-0.11.1-rc.0.tgz 6.5 kB
aws-lambda-powertools-logger-0.11.1-rc.0.tgz 23.8 kB
aws-lambda-powertools-metrics-0.11.1-rc.0.tgz 17.5 kB
commons-bundle.zip 7.1 kB
logger-bundle.zip 24.3 kB
metrics-bundle.zip 18.1 kB

🤖 This report was automatically generated by pkg-size-action
(options hash: 1e8578a5bf31b1b527d58cd1b71ed88b)

@dreamorosi
Copy link
Contributor Author

@dreamorosi dreamorosi requested a review from ijemmy July 5, 2022 10:19
@dreamorosi dreamorosi merged commit 024d628 into main Jul 8, 2022
@dreamorosi dreamorosi deleted the feat/disable_tracer_amplify_mock branch July 8, 2022 12:08
dreamorosi added a commit that referenced this pull request Aug 2, 2022
* feat: disable tracer when running in amplify mock

* chore: housekeeping typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: disable automatically when running inside fn mocked with Amplify CLI
3 participants