-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(aws): Create unified lambda layer for ESM and CJS #17012
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e835e3
feat(aws): Create unified lambda layer for ESM and CJS
msonnb c8d2771
add e2e test
msonnb a1c28f6
formatting
msonnb dd4971f
remove minifying for now
msonnb 04a8f62
apply suggestions fromcode review
msonnb 4ad4e49
fix package.json comment
msonnb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/.npmrc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
23 changes: 23 additions & 0 deletions
23
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "aws-lambda-layer-esm", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node src/run.mjs", | ||
"test": "playwright test", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:build": "pnpm install", | ||
"test:assert": "pnpm test" | ||
}, | ||
"//": "Link from local Lambda layer build", | ||
"dependencies": { | ||
"@sentry/aws-serverless": "link:../../../../packages/aws-serverless/build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless" | ||
}, | ||
"devDependencies": { | ||
"@sentry-internal/test-utils": "link:../../../test-utils", | ||
"@playwright/test": "~1.53.2" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/playwright.config.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
export default getPlaywrightConfig(); |
21 changes: 21 additions & 0 deletions
21
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/src/lambda-function.mjs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as Sentry from '@sentry/aws-serverless'; | ||
|
||
import * as http from 'node:http'; | ||
|
||
async function handle() { | ||
await Sentry.startSpan({ name: 'manual-span', op: 'test' }, async () => { | ||
await new Promise(resolve => { | ||
http.get('http://example.com', res => { | ||
res.on('data', d => { | ||
process.stdout.write(d); | ||
}); | ||
|
||
res.on('end', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
export { handle }; |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/src/run-lambda.mjs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { handle } from './lambda-function.mjs'; | ||
|
||
const event = {}; | ||
const context = { | ||
invokedFunctionArn: 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda', | ||
functionName: 'my-lambda', | ||
}; | ||
await handle(event, context); |
17 changes: 17 additions & 0 deletions
17
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/src/run.mjs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import child_process from 'node:child_process'; | ||
|
||
child_process.execSync('node ./src/run-lambda.mjs', { | ||
stdio: 'inherit', | ||
env: { | ||
...process.env, | ||
// On AWS, LAMBDA_TASK_ROOT is usually /var/task but for testing, we set it to the CWD to correctly apply our handler | ||
LAMBDA_TASK_ROOT: process.cwd(), | ||
_HANDLER: 'src/lambda-function.handle', | ||
|
||
NODE_OPTIONS: '--import @sentry/aws-serverless/awslambda-auto', | ||
SENTRY_DSN: 'http://public@localhost:3031/1337', | ||
SENTRY_TRACES_SAMPLE_RATE: '1.0', | ||
SENTRY_DEBUG: 'true', | ||
}, | ||
cwd: process.cwd(), | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/start-event-proxy.mjs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
||
startEventProxyServer({ | ||
port: 3031, | ||
proxyServerName: 'aws-lambda-layer-esm', | ||
}); |
72 changes: 72 additions & 0 deletions
72
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/tests/basic.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as child_process from 'child_process'; | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
||
test('Lambda layer SDK bundle sends events', async ({ request }) => { | ||
const transactionEventPromise = waitForTransaction('aws-lambda-layer-esm', transactionEvent => { | ||
return transactionEvent?.transaction === 'my-lambda'; | ||
}); | ||
|
||
// Waiting for 1s here because attaching the listener for events in `waitForTransaction` is not synchronous | ||
// Since in this test, we don't start a browser via playwright, we don't have the usual delays (page.goto, etc) | ||
// which are usually enough for us to never have noticed this race condition before. | ||
// This is a workaround but probably sufficient as long as we only experience it in this test. | ||
await new Promise<void>(resolve => | ||
setTimeout(() => { | ||
resolve(); | ||
}, 1000), | ||
); | ||
|
||
child_process.execSync('pnpm start', { | ||
stdio: 'ignore', | ||
}); | ||
|
||
const transactionEvent = await transactionEventPromise; | ||
|
||
// shows the SDK sent a transaction | ||
expect(transactionEvent.transaction).toEqual('my-lambda'); // name should be the function name | ||
expect(transactionEvent.contexts?.trace).toEqual({ | ||
data: { | ||
'sentry.sample_rate': 1, | ||
'sentry.source': 'custom', | ||
'sentry.origin': 'auto.otel.aws-lambda', | ||
'sentry.op': 'function.aws.lambda', | ||
'cloud.account.id': '123453789012', | ||
'faas.id': 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda', | ||
'faas.coldstart': true, | ||
'otel.kind': 'SERVER', | ||
}, | ||
op: 'function.aws.lambda', | ||
origin: 'auto.otel.aws-lambda', | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
status: 'ok', | ||
trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
}); | ||
|
||
expect(transactionEvent.spans).toHaveLength(2); | ||
|
||
// shows that the Otel Http instrumentation is working | ||
expect(transactionEvent.spans).toContainEqual( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'sentry.op': 'http.client', | ||
'sentry.origin': 'auto.http.otel.http', | ||
url: 'http://example.com/', | ||
}), | ||
description: 'GET http://example.com/', | ||
op: 'http.client', | ||
}), | ||
); | ||
|
||
// shows that the manual span creation is working | ||
expect(transactionEvent.spans).toContainEqual( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'sentry.op': 'test', | ||
'sentry.origin': 'manual', | ||
}), | ||
description: 'manual-span', | ||
op: 'test', | ||
}), | ||
); | ||
}); |
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
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
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.