Skip to content

Commit 678d6e8

Browse files
msonnbmydea
andauthored
feat(aws): Enable Lambda extension by default when using the Lamba layer (#17684)
Enables the Lambda extension by default when using the Lambda layer --------- Co-authored-by: Francesco Gringl-Novy <francesco.novy@sentry.io>
1 parent c084bd6 commit 678d6e8

File tree

4 files changed

+48
-87
lines changed

4 files changed

+48
-87
lines changed

dev-packages/e2e-tests/test-applications/aws-serverless/src/lambda-functions-layer/ExperimentalExtension/index.mjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

dev-packages/e2e-tests/test-applications/aws-serverless/tests/layer.test.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -242,52 +242,4 @@ test.describe('Lambda layer', () => {
242242
}),
243243
);
244244
});
245-
246-
test('experimental extension works', async ({ lambdaClient }) => {
247-
const transactionEventPromise = waitForTransaction('aws-serverless-lambda-sam', transactionEvent => {
248-
return transactionEvent?.transaction === 'LayerExperimentalExtension';
249-
});
250-
251-
await lambdaClient.send(
252-
new InvokeCommand({
253-
FunctionName: 'LayerExperimentalExtension',
254-
Payload: JSON.stringify({}),
255-
}),
256-
);
257-
258-
const transactionEvent = await transactionEventPromise;
259-
260-
expect(transactionEvent.transaction).toEqual('LayerExperimentalExtension');
261-
expect(transactionEvent.contexts?.trace).toEqual({
262-
data: {
263-
'sentry.sample_rate': 1,
264-
'sentry.source': 'custom',
265-
'sentry.origin': 'auto.otel.aws-lambda',
266-
'sentry.op': 'function.aws.lambda',
267-
'cloud.account.id': '012345678912',
268-
'faas.execution': expect.any(String),
269-
'faas.id': 'arn:aws:lambda:us-east-1:012345678912:function:LayerExperimentalExtension',
270-
'faas.coldstart': true,
271-
'otel.kind': 'SERVER',
272-
},
273-
op: 'function.aws.lambda',
274-
origin: 'auto.otel.aws-lambda',
275-
span_id: expect.stringMatching(/[a-f0-9]{16}/),
276-
status: 'ok',
277-
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
278-
});
279-
280-
expect(transactionEvent.spans).toHaveLength(1);
281-
282-
expect(transactionEvent.spans).toContainEqual(
283-
expect.objectContaining({
284-
data: expect.objectContaining({
285-
'sentry.op': 'test',
286-
'sentry.origin': 'manual',
287-
}),
288-
description: 'manual-span',
289-
op: 'test',
290-
}),
291-
);
292-
});
293245
});

packages/aws-serverless/src/init.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
1515
}
1616

1717
export interface AwsServerlessOptions extends NodeOptions {
18-
_experiments?: NodeOptions['_experiments'] & {
19-
/**
20-
* If proxying Sentry events through the Sentry Lambda extension should be enabled.
21-
*/
22-
enableLambdaExtension?: boolean;
23-
};
18+
/**
19+
* If Sentry events should be proxied through the Lambda extension when using the Lambda layer. Defaults to `true` when using the Lambda layer.
20+
*/
21+
useLayerExtension?: boolean;
2422
}
2523

2624
/**
@@ -29,14 +27,14 @@ export interface AwsServerlessOptions extends NodeOptions {
2927
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
3028
*/
3129
export function init(options: AwsServerlessOptions = {}): NodeClient | undefined {
30+
const sdkSource = getSDKSource();
3231
const opts = {
3332
defaultIntegrations: getDefaultIntegrations(options),
33+
useLayerExtension: sdkSource === 'aws-lambda-layer' && !options.tunnel,
3434
...options,
3535
};
3636

37-
const sdkSource = getSDKSource();
38-
39-
if (opts._experiments?.enableLambdaExtension) {
37+
if (opts.useLayerExtension) {
4038
if (sdkSource === 'aws-lambda-layer') {
4139
if (!opts.tunnel) {
4240
DEBUG_BUILD && debug.log('Proxying Sentry events through the Sentry Lambda extension');

packages/aws-serverless/test/init.test.ts

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ const mockGetSDKSource = vi.mocked(getSDKSource);
1818
const mockInitWithoutDefaultIntegrations = vi.mocked(initWithoutDefaultIntegrations);
1919

2020
describe('init', () => {
21-
describe('experimental Lambda extension support', () => {
21+
describe('Lambda extension setup', () => {
2222
test('should preserve user-provided tunnel option when Lambda extension is enabled', () => {
2323
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
2424
const options: AwsServerlessOptions = {
2525
tunnel: 'https://custom-tunnel.example.com',
26-
_experiments: {
27-
enableLambdaExtension: true,
28-
},
26+
useLayerExtension: true,
2927
};
3028

3129
init(options);
@@ -40,9 +38,7 @@ describe('init', () => {
4038
test('should set default tunnel when Lambda extension is enabled and SDK source is aws-lambda-layer', () => {
4139
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
4240
const options: AwsServerlessOptions = {
43-
_experiments: {
44-
enableLambdaExtension: true,
45-
},
41+
useLayerExtension: true,
4642
};
4743

4844
init(options);
@@ -57,9 +53,7 @@ describe('init', () => {
5753
test('should not set tunnel when Lambda extension is disabled', () => {
5854
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
5955
const options: AwsServerlessOptions = {
60-
_experiments: {
61-
enableLambdaExtension: false,
62-
},
56+
useLayerExtension: false,
6357
};
6458

6559
init(options);
@@ -74,9 +68,7 @@ describe('init', () => {
7468
test('should not set tunnel when SDK source is not aws-lambda-layer even with Lambda extension enabled', () => {
7569
mockGetSDKSource.mockReturnValue('npm');
7670
const options: AwsServerlessOptions = {
77-
_experiments: {
78-
enableLambdaExtension: true,
79-
},
71+
useLayerExtension: true,
8072
};
8173

8274
init(options);
@@ -88,17 +80,52 @@ describe('init', () => {
8880
);
8981
});
9082

91-
test('should not set tunnel when no experiments are provided', () => {
83+
test('should default useLayerExtension to true when SDK source is aws-lambda-layer', () => {
9284
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
9385
const options: AwsServerlessOptions = {};
9486

9587
init(options);
9688

89+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
90+
expect.objectContaining({
91+
useLayerExtension: true,
92+
tunnel: 'http://localhost:9000/envelope',
93+
}),
94+
);
95+
});
96+
97+
test('should default useLayerExtension to false when SDK source is not aws-lambda-layer', () => {
98+
mockGetSDKSource.mockReturnValue('npm');
99+
const options: AwsServerlessOptions = {};
100+
101+
init(options);
102+
103+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
104+
expect.objectContaining({
105+
useLayerExtension: false,
106+
}),
107+
);
97108
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
98109
expect.not.objectContaining({
99110
tunnel: expect.any(String),
100111
}),
101112
);
102113
});
114+
115+
test('should default useLayerExtension to false when tunnel is provided even when SDK source is aws-lambda-layer', () => {
116+
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
117+
const options: AwsServerlessOptions = {
118+
tunnel: 'https://custom-tunnel.example.com',
119+
};
120+
121+
init(options);
122+
123+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
124+
expect.objectContaining({
125+
useLayerExtension: false,
126+
tunnel: 'https://custom-tunnel.example.com',
127+
}),
128+
);
129+
});
103130
});
104131
});

0 commit comments

Comments
 (0)