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

test(e2e): Add e2e test for AWS lambda in ESM mode #12833

Merged
merged 7 commits into from
Jul 10, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jul 9, 2024

This PR adds an E2E test app that simulates running an AWS lambda function in ESM mode. At the same time, this test app represents the state of how to manually use the @sentry/aws-serverless SDK for ESM-based lambda functions. For the moment, the plan is to document this as follows:

  1. Install @sentry/aws-serverless with the package manager of your choice
  2. Add the following environment variables to your lambda environment:
    • NODE_OPTIONS: '--import @sentry/aws-serverless/awslambda-auto
    • SENTRY_DSN: '<your-dsn>'
    • SENTRY_TRACES_SAMPLE_RATE: '1.0'
  3. wrap your lambda handler function with Sentry.wrapHandler
  4. ensure that when deploying your function, the node_modules directory is deployed alongside your lambda code

Unfortunately, we can't get around highest friction points:

  • manually adding the Sentry.wrapHandler wrapper
  • ensuring the SDK + dependencies in node_modules are deployed alongside lambda code

This, we'll only get rid off with an ESM lambda layer, and possibly not at all for the Sentry.wrapHandler part.

ref #12409

@Lms24 Lms24 requested a review from andreiborza July 9, 2024 13:56
@@ -23,7 +23,8 @@
"esbuild": "0.20.0",
"glob": "8.0.3",
"ts-node": "10.9.1",
"yaml": "2.2.2"
"yaml": "2.2.2",
"rimraf": "^5.0.0"
Copy link
Member Author

@Lms24 Lms24 Jul 9, 2024

Choose a reason for hiding this comment

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

not sure why but without adding rimraf explicitly here, I can't use the yarn test:run command to run e2e tests locally as rimraf isn't found otherwise 🤔

@Lms24 Lms24 force-pushed the lms/test-aws-serverless-esm branch from 5b962b7 to 8d1fa8f Compare July 9, 2024 14:35
@Lms24 Lms24 self-assigned this Jul 9, 2024
@Lms24 Lms24 marked this pull request as ready for review July 9, 2024 15:33
@Lms24 Lms24 requested review from lforst and AbhiPrasad July 9, 2024 15:33

const handler = Sentry.wrapHandler(async () => {
await new Promise(resolve => {
const req = http.request(
Copy link
Member Author

@Lms24 Lms24 Jul 9, 2024

Choose a reason for hiding this comment

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

took me ages to find out why the previously used http.get call didn't produce a span. Turns out it's an Otel ESM bug. Reported it to Otel here: open-telemetry/opentelemetry-js#4857

Anyway, this http.request call now emits a span which we assert on in the test. So this shows that otel instrumentation generally works

Copy link
Member

Choose a reason for hiding this comment

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

nice find

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

really nice to have an e2e test for this!

Comment on lines +15 to +25
{
/* Run your local dev server before starting the tests */
webServer: [
{
command: `node start-event-proxy.mjs && pnpm wait-port ${eventProxyPort}`,
port: eventProxyPort,
stdout: 'pipe',
},
],
},
);
Copy link
Member

@andreiborza andreiborza Jul 10, 2024

Choose a reason for hiding this comment

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

l: Is this needed? The base config is already doing this ootb.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, it somewhat is necessary because the shared playwright config always expects an additional startCommand to start an application/development server. For our AWS Lambda tests, we don't need this because we invoke the function from within the test file. I'll open a separate PR to make startCommand optional since this concerns all e2e tests relying on the shared config.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, understood. Thanks for the explanation!

Copy link
Member Author

Choose a reason for hiding this comment

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

PR to refactor: #12842

@Lms24 Lms24 merged commit ed3d12f into develop Jul 10, 2024
120 of 121 checks passed
@Lms24 Lms24 deleted the lms/test-aws-serverless-esm branch July 10, 2024 07:45
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.

2 participants