Skip to content

Commit 8a85d2d

Browse files
committed
fix(aws-serverless): Keep the Lambda extension for a relative tunnel path, which is the managed tunnel to serve
1 parent 7497f59 commit 8a85d2d

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎packages/aws-serverless/src/init.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,24 @@ export function init(options: AwsServerlessOptions = {}): NodeClient | undefined
7777
// 2. Environment variable SENTRY_LAYER_EXTENSION (if set)
7878
// 3. Default logic based on sdkSource, tunnel, and proxy settings
7979
const useLayerExtensionFromEnv = envToBool(process.env.SENTRY_LAYER_EXTENSION, { strict: true });
80-
const defaultUseLayerExtension =
81-
sdkSource === 'aws-lambda-layer' && typeof options.tunnel !== 'string' && !proxyWouldInterfere;
80+
// A relative path is the managed tunnel's path, not a transport URL.
81+
const { tunnel, _managedTunnel } = resolveServerTunnelOption(options.tunnel);
82+
const defaultUseLayerExtension = sdkSource === 'aws-lambda-layer' && !tunnel && !proxyWouldInterfere;
8283
const useLayerExtension = options.useLayerExtension ?? useLayerExtensionFromEnv ?? defaultUseLayerExtension;
8384

8485
const opts = {
8586
defaultIntegrations: getDefaultIntegrations(options),
8687
useLayerExtension,
8788
...options,
89+
tunnel,
90+
_managedTunnel,
8891
};
8992

9093
if (opts.useLayerExtension) {
9194
if (sdkSource !== 'aws-lambda-layer') {
9295
DEBUG_BUILD && debug.warn('The Sentry Lambda extension is only supported when using the AWS Lambda layer.');
93-
} else if (typeof opts.tunnel === 'string' || proxyWouldInterfere) {
94-
if (typeof opts.tunnel === 'string') {
96+
} else if (opts.tunnel || proxyWouldInterfere) {
97+
if (opts.tunnel) {
9598
DEBUG_BUILD &&
9699
debug.warn(
97100
`Using a custom tunnel with the Sentry Lambda extension is not supported. Events will be tunnelled to ${opts.tunnel} and not through the extension.`,
@@ -106,8 +109,6 @@ export function init(options: AwsServerlessOptions = {}): NodeClient | undefined
106109
}
107110
} else {
108111
DEBUG_BUILD && debug.log('Proxying Sentry events through the Sentry Lambda extension');
109-
// The extension takes over the transport, but the managed tunnel is still served.
110-
opts._managedTunnel = resolveServerTunnelOption(opts.tunnel)._managedTunnel;
111112
opts.tunnel = 'http://localhost:9000/envelope';
112113
}
113114
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ describe('init', () => {
7373
);
7474
});
7575

76+
test('keeps the Lambda extension for a relative tunnel path, which is the managed tunnel to serve', () => {
77+
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
78+
79+
init({ tunnel: '/monitor' });
80+
81+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
82+
expect.objectContaining({
83+
useLayerExtension: true,
84+
tunnel: 'http://localhost:9000/envelope',
85+
_managedTunnel: { path: '/monitor' },
86+
}),
87+
);
88+
});
89+
7690
test('should not set tunnel when Lambda extension is disabled', () => {
7791
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
7892
const options: AwsServerlessOptions = {

0 commit comments

Comments
 (0)