-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aws-serverless): Only start root span in Sentry wrapper if Otel d…
…idn't wrap handler (#12407) Fix span collision by checking if the AWS lambda handler was already wrapped by Otel instrumentation and only if not starting our own root span. The rest of our handler is still being used (i.e. the flushing logic, error capturing, etc) regardless of otel wrapping. Also Adjusted E2E tests to: - more closely resemble the AWS environment - enable auto patching of the handler with the Sentry SDK handler - better check for Otel and manual spans Ref #12409
- Loading branch information
Showing
13 changed files
with
125 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
dev-packages/e2e-tests/test-applications/aws-lambda-layer-cjs/src/lambda-function.js
This file contains 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 @@ | ||
const Sentry = require('@sentry/aws-serverless'); | ||
|
||
const http = require('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(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { handle }; |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/aws-lambda-layer-cjs/src/run-lambda.js
This file contains 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,7 @@ | ||
const { handle } = require('./lambda-function'); | ||
const event = {}; | ||
const context = { | ||
invokedFunctionArn: 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda', | ||
functionName: 'my-lambda', | ||
}; | ||
handle(event, context); |
This file contains 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 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
69 changes: 69 additions & 0 deletions
69
dev-packages/e2e-tests/test-applications/aws-lambda-layer-cjs/tests/basic.test.ts
This file contains 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,69 @@ | ||
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-serverless-lambda-layer-cjs', 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', | ||
'cloud.account.id': '123453789012', | ||
'faas.id': 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda', | ||
'otel.kind': 'SERVER', | ||
}, | ||
origin: 'auto.otel.aws-lambda', | ||
span_id: expect.any(String), | ||
status: 'ok', | ||
trace_id: expect.any(String), | ||
}); | ||
|
||
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', | ||
}), | ||
); | ||
}); |
19 changes: 0 additions & 19 deletions
19
dev-packages/e2e-tests/test-applications/aws-lambda-layer/src/lambda-function.js
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
dev-packages/e2e-tests/test-applications/aws-lambda-layer/src/run-lambda.js
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
dev-packages/e2e-tests/test-applications/aws-lambda-layer/tests/basic.test.ts
This file was deleted.
Oops, something went wrong.
This file contains 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