GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(aws-serverless): Keep the Lambda extension enabled when http_proxy is set by msonnb · Pull Request #26360 · getsentry/sentry-javascript

feat(aws-serverless): Keep the Lambda extension enabled when http_proxy is set #26360

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.

Sign up for GitHub

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
msonnb merged 3 commits into ms/lambda-extension-http-proxy from ms/lambda-extension-proxy-default
Nov 18, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(aws-serverless): Keep the Lambda extension enabled when http_proxy is set #26360

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
9e7a258
feat(aws-serverless): Keep the Lambda extension enabled when http_pro…
msonnb Nov 13, 2026
51aa4be
test(aws-serverless): Send events through the Lambda extension and ht…
msonnb Nov 13, 2026
fccfae0
ref(aws-serverless): Flatten the Lambda extension fallback branches
msonnb Nov 16, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

3 changes: 3 additions & 0 deletions 3 ...ests/test-applications/aws-serverless-layer/src/lambda-functions-layer/HttpProxy/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.handler = async () => {
throw new Error('http-proxy-test');
};
6 changes: 4 additions & 2 deletions 6 dev-packages/e2e-tests/test-applications/aws-serverless-layer/src/stack.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const LAMBDA_FUNCTION_TIMEOUT = 10;
const LAYER_DIR = './node_modules/@sentry/aws-serverless/';
// SAM allocates runtime container ports in [5000, 9000) before binding its own endpoint.
export const SAM_PORT = Number(process.env.SAM_PORT) || 17120;
export const HTTP_PROXY_PORT = 3032;

/** Match SAM / Docker to this machine so Apple Silicon does not mix arm64 images with an x86_64 template default. */
function samLambdaArchitecture(): 'arm64' | 'x86_64' {
Expand Down Expand Up @@ -48,10 +49,10 @@ export class LocalLambdaStack extends Stack {
const dsn = `http://public@${hostIp}:3031/1337`;
console.log(`[LocalLambdaStack] Using Sentry DSN: ${dsn}`);

this.addLambdaFunctions(dsn);
this.addLambdaFunctions(dsn, hostIp);
}

private addLambdaFunctions(dsn: string) {
private addLambdaFunctions(dsn: string, hostIp: string) {
console.log(`[LocalLambdaStack] Add all Lambda functions defined in ${LAMBDA_FUNCTIONS_DIR} to the SAM stack`);

const lambdaDirs = fs
Expand Down Expand Up @@ -84,6 +85,7 @@ export class LocalLambdaStack extends Stack {
// we want to test that the extension tunnel forwards requests when SENTRY_DSN is missing.
TUNNEL_TEST_DSN: dsn,
...(lambdaDir !== 'TunnelNoDsn' ? { SENTRY_DSN: dsn } : {}),
...(lambdaDir === 'HttpProxy' ? { http_proxy: `http://${hostIp}:${HTTP_PROXY_PORT}` } : {}),
},
},
},
Expand Down
59 changes: 59 additions & 0 deletions 59 dev-packages/e2e-tests/test-applications/aws-serverless-layer/tests/layer.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { waitForTransaction, waitForError, waitForRequest } from '@sentry-internal/test-utils';
import { InvokeCommand } from '@aws-sdk/client-lambda';
import * as http from 'node:http';
import * as net from 'node:net';
import { once } from 'node:events';
import { HTTP_PROXY_PORT } from '../src/stack';
import { test, expect } from './lambda-fixtures';

interface TunnelInvokeResult {
Expand All @@ -8,6 +12,37 @@ interface TunnelInvokeResult {
responseBody: string;
}

/**
* A forward proxy that records each CONNECT target. The Lambda container reaches the host through its host IP, which
* may not resolve on the host itself, so every tunnel goes to the same port on loopback.
*/
async function startConnectProxy(): Promise<{ connects: string[]; close: () => Promise<void> }> {
const connects: string[] = [];
const server = http.createServer();
server.on('connect', (req: http.IncomingMessage, clientSocket: net.Socket) => {
const target = req.url ?? '';
connects.push(target);
const upstream = net.connect(Number(target.split(':').pop()), '127.0.0.1', () => {
clientSocket.write('HTTP/1.1 200 Connection Established\r\n\r\n');
upstream.pipe(clientSocket);
clientSocket.pipe(upstream);
});
upstream.on('error', () => clientSocket.destroy());
clientSocket.on('error', () => upstream.destroy());
});
server.listen(HTTP_PROXY_PORT, '0.0.0.0');
await once(server, 'listening');

return {
connects,
close: () =>
new Promise(resolve => {
server.closeAllConnections();
server.close(() => resolve());
}),
};
}

function parseLambdaPayload(payload: Uint8Array | undefined): TunnelInvokeResult {
if (!payload) {
throw new Error('Missing Lambda payload');
Expand Down Expand Up @@ -421,6 +456,30 @@ test.describe('Lambda layer', () => {
expect(secondErrorEvent.tags?.invocation_tag).toBeUndefined();
});

test('sends events through the extension and http_proxy', async ({ lambdaClient }) => {
const proxy = await startConnectProxy();

try {
const requestPromise = waitForRequest('aws-serverless-layer', requestData => {
return requestData.rawProxyRequestBody.includes('http-proxy-test');
});

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

const request = await requestPromise;

// The SDK only puts the DSN in the envelope header when it sends through a tunnel, i.e. the extension.
const envelopeHeader = JSON.parse(request.rawProxyRequestBody.split('\n')[0] ?? '{}');
expect(envelopeHeader.dsn).toEqual(expect.stringContaining(':3031/1337'));

// The extension went through the proxy, and the SDK reached the extension without it.
expect(proxy.connects.length).toBeGreaterThan(0);
expect(proxy.connects.every(target => target.endsWith(':3031'))).toBe(true);
} finally {
await proxy.close();
}
});

test('extension tunnel validates DSN allowlist and rejects invalid envelopes', async ({ lambdaClient }) => {
const matchingMarker = `extension-tunnel-matching-${Date.now()}`;
const matchingRequestPromise = waitForRequest('aws-serverless-layer', requestData => {
Expand Down
69 changes: 19 additions & 50 deletions 69 packages/aws-serverless/src/init.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,11 @@ const STATIC_ASSET_INVOCATIONS: NonNullable<Options['ignoreSpans']> = [
];

/**
* Checks if proxy environment variables would interfere with the layer extension.
* The layer extension uses localhost:9000, so we need to check if proxy settings would prevent this.
* The Lambda extension only reads proxy settings from env vars, so it can't apply a proxy or CA certificates set in
* `transportOptions`.
*/
function shouldDisableLayerExtensionForProxy(): boolean {
const { http_proxy, no_proxy } = process.env;

// If no http proxy is configured, no interference (https_proxy doesn't affect HTTP requests)
if (!http_proxy) {
return false;
}

// Check if localhost is exempted by no_proxy
if (no_proxy) {
const exemptions = no_proxy.split(',').map(exemption => exemption.trim().toLowerCase());

// Handle common localhost exemption patterns explicitly
// If localhost is exempted, requests to the layer extension will not be proxied
const localhostExemptions = ['*', 'localhost', '127.0.0.1', '::1'];
if (exemptions.some(exemption => localhostExemptions.includes(exemption))) {
return false;
}
}

// If http_proxy is set and no localhost exemption, it would interfere
// The layer extension uses HTTP to localhost:9000, so only http_proxy matters
if (http_proxy) {
DEBUG_BUILD &&
debug.log(
'Disabling useLayerExtension due to http_proxy environment variable. Consider adding localhost to no_proxy to re-enable.',
);
return true;
}

return false;
function hasProxyTransportOptions(options: AwsServerlessOptions): boolean {
return !!(options.transportOptions?.proxy || options.transportOptions?.caCerts);
}

/**
Expand Down Expand Up @@ -107,14 +78,14 @@ export function getIgnoreSpans(options: AwsServerlessOptions): NonNullable<Optio
*/
export function init(options: AwsServerlessOptions = {}): NodeClient | undefined {
const sdkSource = getSDKSource();
const proxyWouldInterfere = shouldDisableLayerExtensionForProxy();
const hasProxyOptions = hasProxyTransportOptions(options);

// Determine useLayerExtension value with the following priority:
// 1. Explicit option value (if provided)
// 2. Environment variable SENTRY_LAYER_EXTENSION (if set)
// 3. Default logic based on sdkSource, tunnel, and proxy settings
// 3. Default logic based on sdkSource, tunnel, and proxy transport options
const useLayerExtensionFromEnv = envToBool(process.env.SENTRY_LAYER_EXTENSION, { strict: true });
const defaultUseLayerExtension = sdkSource === 'aws-lambda-layer' && !options.tunnel && !proxyWouldInterfere;
const defaultUseLayerExtension = sdkSource === 'aws-lambda-layer' && !options.tunnel && !hasProxyOptions;
Comment thread
msonnb marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

const useLayerExtension = options.useLayerExtension ?? useLayerExtensionFromEnv ?? defaultUseLayerExtension;

const opts = {
Expand All @@ -127,23 +98,21 @@ export function init(options: AwsServerlessOptions = {}): NodeClient | undefined
if (opts.useLayerExtension) {
if (sdkSource !== 'aws-lambda-layer') {
DEBUG_BUILD && debug.warn('The Sentry Lambda extension is only supported when using the AWS Lambda layer.');
} else if (opts.tunnel || proxyWouldInterfere) {
if (opts.tunnel) {
DEBUG_BUILD &&
debug.warn(
`Using a custom tunnel with the Sentry Lambda extension is not supported. Events will be tunnelled to ${opts.tunnel} and not through the extension.`,
);
}

if (proxyWouldInterfere) {
DEBUG_BUILD &&
debug.warn(
'Sentry Lambda extension is disabled due to proxy environment variables (http_proxy/https_proxy). Consider adding localhost to no_proxy to re-enable.',
);
}
} else if (opts.tunnel) {
DEBUG_BUILD &&
debug.warn(
`Using a custom tunnel with the Sentry Lambda extension is not supported. Events will be tunnelled to ${opts.tunnel} and not through the extension.`,
);
} else if (hasProxyOptions) {
DEBUG_BUILD &&
debug.warn(
'Sentry Lambda extension is disabled because `transportOptions` sets a proxy or CA certificates, which the extension cannot apply. Use the `http_proxy`/`https_proxy` and `NODE_EXTRA_CA_CERTS` environment variables instead to keep using the extension.',
);
} else {
DEBUG_BUILD && debug.log('Proxying Sentry events through the Sentry Lambda extension');
opts.tunnel = 'http://localhost:9000/envelope';
// The extension applies proxy env vars itself; requests to it must not go through the proxy.
opts.transportOptions = { ...opts.transportOptions, proxy: false };
}
}

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.