-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(aws-serverless): Emit low cardinality function.aws span names
#24072
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
Lms24
merged 4 commits into
lms/feat-server-utils-firebase-span-names
from
lms/feat-aws-faas-span-names
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa28305
feat(aws-serverless): Emit low cardinality `function.aws` span names
Lms24 81f57e3
convert e2e test to streaming
Lms24 856abec
test(aws-serverless): Drop unit tests covered by the streamed e2e suite
Lms24 7045f2a
feat(aws-serverless): Set `component` as the `function.aws` segment n…
Lms24 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
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 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
208 changes: 73 additions & 135 deletions
208
dev-packages/e2e-tests/test-applications/aws-serverless/tests/npm.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 |
|---|---|---|
| @@ -1,147 +1,85 @@ | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
| import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; | ||
| import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils'; | ||
| import { InvokeCommand } from '@aws-sdk/client-lambda'; | ||
| import { test, expect } from './lambda-fixtures'; | ||
|
|
||
| test.describe('NPM package', () => { | ||
| test('tracing in CJS works', async ({ lambdaClient }) => { | ||
| const transactionEventPromise = waitForTransaction('aws-serverless', transactionEvent => { | ||
| return transactionEvent?.transaction === 'NpmTracingCjs'; | ||
| }); | ||
|
|
||
| await lambdaClient.send( | ||
| new InvokeCommand({ | ||
| FunctionName: 'NpmTracingCjs', | ||
| Payload: JSON.stringify({}), | ||
| }), | ||
| ); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| // shows the SDK sent a transaction | ||
| expect(transactionEvent.transaction).toEqual('NpmTracingCjs'); // name should be the function name | ||
| expect(transactionEvent.contexts?.trace).toEqual({ | ||
| data: { | ||
| 'sentry.sample_rate': 1, | ||
| 'sentry.segment.name.source': 'custom', | ||
| 'sentry.origin': 'auto.aws_lambda', | ||
| 'sentry.op': 'function.aws', | ||
| 'cloud.account.id': '012345678912', | ||
| 'cloud.platform': 'aws_lambda', | ||
| 'cloud.provider': 'aws', | ||
| 'faas.execution': expect.any(String), | ||
| 'faas.id': 'arn:aws:lambda:us-east-1:012345678912:function:NpmTracingCjs', | ||
| 'faas.name': 'NpmTracingCjs', | ||
| 'faas.coldstart': true, | ||
| 'sentry.kind': 'server', | ||
| }, | ||
| op: 'function.aws', | ||
| origin: 'auto.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); | ||
| // This app runs with `traceLifecycle: 'stream'`, the SDK default. The `aws-serverless-layer` app | ||
| // covers the `'static'` lifecycle, so between the two both lifecycles stay under test. | ||
|
|
||
| function assertLambdaTrace(spans: SerializedStreamedSpan[], functionName: string): void { | ||
| const segmentSpan = spans.find(span => span.is_segment); | ||
|
|
||
| // `function.aws` span names are low cardinality: the function name, never the invocation URL. | ||
| expect(segmentSpan?.name).toBe(functionName); | ||
| expect(segmentSpan?.status).toBe('ok'); | ||
| expect(getSpanOp(segmentSpan!)).toBe('function.aws'); | ||
|
|
||
| expect(segmentSpan?.attributes).toMatchObject({ | ||
| 'sentry.op': { value: 'function.aws', type: 'string' }, | ||
| 'sentry.origin': { value: 'auto.aws_lambda', type: 'string' }, | ||
| 'sentry.kind': { value: 'server', type: 'string' }, | ||
| 'sentry.segment.name.source': { value: 'component', type: 'string' }, | ||
| 'cloud.account.id': { value: '012345678912', type: 'string' }, | ||
| 'cloud.platform': { value: 'aws_lambda', type: 'string' }, | ||
| 'cloud.provider': { value: 'aws', type: 'string' }, | ||
| 'faas.coldstart': { value: true, type: 'boolean' }, | ||
| 'faas.execution': { value: expect.any(String), type: 'string' }, | ||
| 'faas.id': { value: `arn:aws:lambda:us-east-1:012345678912:function:${functionName}`, type: 'string' }, | ||
| // The name the span is named after also stays on the span, so it survives a rename. | ||
| 'faas.name': { value: functionName, type: 'string' }, | ||
| // Streamed spans have no event contexts, so the `aws.lambda` context the transaction used to | ||
| // carry is stamped onto the segment span by `awsLambdaIntegration`. | ||
| 'aws.lambda.function_name': { value: functionName, type: 'string' }, | ||
| 'aws.lambda.invoked_function_arn': { | ||
| value: `arn:aws:lambda:us-east-1:012345678912:function:${functionName}`, | ||
| type: 'string', | ||
| }, | ||
| 'aws.lambda.aws_request_id': { value: expect.any(String), type: 'string' }, | ||
| 'aws.cloudwatch.logs.log_group': { value: expect.any(String), type: 'string' }, | ||
| 'aws.cloudwatch.logs.log_stream': { value: expect.any(String), type: 'string' }, | ||
| }); | ||
|
|
||
| // 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.client', | ||
| 'url.full': 'http://example.com/', | ||
| }), | ||
| description: 'GET http://example.com/', | ||
| op: 'http.client', | ||
| // shows that the Otel Http instrumentation is working | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| name: 'GET example.com', | ||
| parent_span_id: segmentSpan?.span_id, | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.op': { value: 'http.client', type: 'string' }, | ||
| 'sentry.origin': { value: 'auto.http.client', type: 'string' }, | ||
| 'url.full': { value: 'http://example.com/', type: 'string' }, | ||
| }), | ||
| ); | ||
|
|
||
| // shows that the manual span creation is working | ||
| expect(transactionEvent.spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'manual', | ||
| 'sentry.origin': 'manual', | ||
| }), | ||
| description: 'manual-span', | ||
| op: 'manual', | ||
| }), | ||
| ); | ||
|
|
||
| // shows that the manual span creation is working | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| name: 'manual-span', | ||
| parent_span_id: segmentSpan?.span_id, | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.op': { value: 'manual', type: 'string' }, | ||
| 'sentry.origin': { value: 'manual', type: 'string' }, | ||
| }), | ||
| ); | ||
|
|
||
| // shows that the SDK source is correctly detected | ||
| expect(transactionEvent.sdk?.packages).toContainEqual( | ||
| expect.objectContaining({ name: 'npm:@sentry/aws-serverless' }), | ||
| ); | ||
| }); | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| test('tracing in ESM works', async ({ lambdaClient }) => { | ||
| const transactionEventPromise = waitForTransaction('aws-serverless', transactionEvent => { | ||
| return transactionEvent?.transaction === 'NpmTracingEsm'; | ||
| }); | ||
| test.describe('NPM package', () => { | ||
| for (const [label, functionName] of [ | ||
| ['CJS', 'NpmTracingCjs'], | ||
| ['ESM', 'NpmTracingEsm'], | ||
| ] as const) { | ||
| test(`tracing in ${label} works`, async ({ lambdaClient }) => { | ||
| const spansPromise = collectStreamedSpans('aws-serverless', spansOfTrace => | ||
| spansOfTrace.some(span => span.is_segment && span.name === functionName), | ||
| ); | ||
|
|
||
| await lambdaClient.send( | ||
| new InvokeCommand({ | ||
| FunctionName: 'NpmTracingEsm', | ||
| Payload: JSON.stringify({}), | ||
| }), | ||
| ); | ||
| await lambdaClient.send(new InvokeCommand({ FunctionName: functionName, Payload: JSON.stringify({}) })); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const spans = await spansPromise; | ||
|
|
||
| // shows the SDK sent a transaction | ||
| expect(transactionEvent.transaction).toEqual('NpmTracingEsm'); // name should be the function name | ||
| expect(transactionEvent.contexts?.trace).toEqual({ | ||
| data: { | ||
| 'sentry.sample_rate': 1, | ||
| 'sentry.segment.name.source': 'custom', | ||
| 'sentry.origin': 'auto.aws_lambda', | ||
| 'sentry.op': 'function.aws', | ||
| 'cloud.account.id': '012345678912', | ||
| 'cloud.platform': 'aws_lambda', | ||
| 'cloud.provider': 'aws', | ||
| 'faas.execution': expect.any(String), | ||
| 'faas.id': 'arn:aws:lambda:us-east-1:012345678912:function:NpmTracingEsm', | ||
| 'faas.name': 'NpmTracingEsm', | ||
| 'faas.coldstart': true, | ||
| 'sentry.kind': 'server', | ||
| }, | ||
| op: 'function.aws', | ||
| origin: 'auto.aws_lambda', | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| status: 'ok', | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| assertLambdaTrace(spans, functionName); | ||
| }); | ||
|
|
||
| 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.client', | ||
| 'url.full': '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': 'manual', | ||
| 'sentry.origin': 'manual', | ||
| }), | ||
| description: 'manual-span', | ||
| op: 'manual', | ||
| }), | ||
| ); | ||
|
|
||
| // shows that the SDK source is correctly detected | ||
| expect(transactionEvent.sdk?.packages).toContainEqual( | ||
| expect.objectContaining({ name: 'npm:@sentry/aws-serverless' }), | ||
| ); | ||
| }); | ||
| } | ||
| }); |
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.
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.