Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -242,52 +242,4 @@ test.describe('Lambda layer', () => {
}),
);
});

test('experimental extension works', async ({ lambdaClient }) => {
const transactionEventPromise = waitForTransaction('aws-serverless-lambda-sam', transactionEvent => {
return transactionEvent?.transaction === 'LayerExperimentalExtension';
});

await lambdaClient.send(
new InvokeCommand({
FunctionName: 'LayerExperimentalExtension',
Payload: JSON.stringify({}),
}),
);

const transactionEvent = await transactionEventPromise;

expect(transactionEvent.transaction).toEqual('LayerExperimentalExtension');
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': '012345678912',
'faas.execution': expect.any(String),
'faas.id': 'arn:aws:lambda:us-east-1:012345678912:function:LayerExperimentalExtension',
'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(1);

expect(transactionEvent.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'sentry.op': 'test',
'sentry.origin': 'manual',
}),
description: 'manual-span',
op: 'test',
}),
);
});
});
16 changes: 7 additions & 9 deletions packages/aws-serverless/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
}

export interface AwsServerlessOptions extends NodeOptions {
_experiments?: NodeOptions['_experiments'] & {
/**
* If proxying Sentry events through the Sentry Lambda extension should be enabled.
*/
enableLambdaExtension?: boolean;
};
/**
* If proxying Sentry events through the Sentry Lambda extension should be enabled. Defaults to `true` when using the AWS Lambda layer.
*/
enableLambdaExtension?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I think I would go with another option, as this does not really control enabling the extension (e.g. you cannot simply set this to true when using the npm package, right?)

Maybe something like:

useLayerExtension?: boolean

or similar, to make it clear that is related to layers and just using it, not enabling it...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that makes more sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I maybe also create an issue for distributing a separate layer with only the extension in it? then npm users could benefit as well

Copy link
Member

Choose a reason for hiding this comment

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

I think I'd leave this for now, if we get this request in the future we can always follow up - for now this is simple enough I'd say :D

}

/**
Expand All @@ -29,14 +27,14 @@ export interface AwsServerlessOptions extends NodeOptions {
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
*/
export function init(options: AwsServerlessOptions = {}): NodeClient | undefined {
const sdkSource = getSDKSource();
const opts = {
defaultIntegrations: getDefaultIntegrations(options),
enableLambdaExtension: sdkSource === 'aws-lambda-layer',
...options,
};

const sdkSource = getSDKSource();

if (opts._experiments?.enableLambdaExtension) {
if (opts.enableLambdaExtension) {
if (sdkSource === 'aws-lambda-layer') {
if (!opts.tunnel) {
DEBUG_BUILD && debug.log('Proxying Sentry events through the Sentry Lambda extension');
Expand Down
39 changes: 25 additions & 14 deletions packages/aws-serverless/test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ const mockGetSDKSource = vi.mocked(getSDKSource);
const mockInitWithoutDefaultIntegrations = vi.mocked(initWithoutDefaultIntegrations);

describe('init', () => {
describe('experimental Lambda extension support', () => {
describe('Lambda extension setup', () => {
test('should preserve user-provided tunnel option when Lambda extension is enabled', () => {
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
const options: AwsServerlessOptions = {
tunnel: 'https://custom-tunnel.example.com',
_experiments: {
enableLambdaExtension: true,
},
enableLambdaExtension: true,
};

init(options);
Expand All @@ -40,9 +38,7 @@ describe('init', () => {
test('should set default tunnel when Lambda extension is enabled and SDK source is aws-lambda-layer', () => {
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
const options: AwsServerlessOptions = {
_experiments: {
enableLambdaExtension: true,
},
enableLambdaExtension: true,
};

init(options);
Expand All @@ -57,9 +53,7 @@ describe('init', () => {
test('should not set tunnel when Lambda extension is disabled', () => {
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
const options: AwsServerlessOptions = {
_experiments: {
enableLambdaExtension: false,
},
enableLambdaExtension: false,
};

init(options);
Expand All @@ -74,9 +68,7 @@ describe('init', () => {
test('should not set tunnel when SDK source is not aws-lambda-layer even with Lambda extension enabled', () => {
mockGetSDKSource.mockReturnValue('npm');
const options: AwsServerlessOptions = {
_experiments: {
enableLambdaExtension: true,
},
enableLambdaExtension: true,
};

init(options);
Expand All @@ -88,12 +80,31 @@ describe('init', () => {
);
});

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

init(options);

expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
expect.objectContaining({
enableLambdaExtension: true,
tunnel: 'http://localhost:9000/envelope',
}),
);
});

test('should default enableLambdaExtension to false when SDK source is not aws-lambda-layer', () => {
mockGetSDKSource.mockReturnValue('npm');
const options: AwsServerlessOptions = {};

init(options);

expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
expect.objectContaining({
enableLambdaExtension: false,
}),
);
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
expect.not.objectContaining({
tunnel: expect.any(String),
Expand Down