From f5f2ec478be34447149cd1c4ab36ed7d00b73e9a Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Mon, 19 Oct 2026 15:40:53 +0200 Subject: [PATCH] Buffer telemetry for 25 ms, Lambda's minimum The extension waits for Lambda's telemetry hand-off at the end of every invocation, and Lambda hands the last batch over only when TIMEOUT_MS expires, so the window is added to every invocation. 25 ms keeps that wait short; Better Stack still gets one request per invocation. Co-Authored-By: Claude Fable 5.1 --- README.md | 2 +- src/env.test.ts | 2 +- src/env.ts | 5 ++++- src/extension.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 15e47fe..c4500f6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ On next invocation your Lambda logs should start appearing in **Telemetry** -> [ | RECEIVER_PORT | Port of the logs http receiver | `4243` | | MAX_ITEMS | Maximum number of events that can be buffered in memory | `10000` | | MAX_BYTES | Maximum size in bytes of events that can be buffered | `262144` | -| TIMEOUT_MS | Maximum time (in milliseconds) that a batch is buffered | `1000` | +| TIMEOUT_MS | Maximum time (in milliseconds) that a batch is buffered | `25` | | AWS_LAMBDA_RUNTIME_API | HTTP base URI to the lambda runtime API | _Provided by AWS Lambda environment_ | | AWS_LAMBDA_RUNTIME_EXTENSION_API_VERSION | Lambda Extension API version date | `2020-01-01` | | AWS_LAMBDA_RUNTIME_TELEMETRY_API_VERSION | Telemetry API version date | `2022-07-01` | diff --git a/src/env.test.ts b/src/env.test.ts index c5164e3..a84d373 100644 --- a/src/env.test.ts +++ b/src/env.test.ts @@ -23,7 +23,7 @@ describe('parseEnvironmentVariables', () => { RECEIVER_ADDRESS: 'sandbox', MAX_ITEMS: 10000, MAX_BYTES: 262144, - TIMEOUT_MS: 1000, + TIMEOUT_MS: 25, RECEIVER_PORT: 4243, sourceToken: 'source_token', ingestionUrl: 'https://s123456.lu-trq-1.betterstackdata.com/', diff --git a/src/env.ts b/src/env.ts index f619904..aed3cc6 100644 --- a/src/env.ts +++ b/src/env.ts @@ -18,7 +18,10 @@ const baseSchema = z.object({ RECEIVER_ADDRESS: z.string().default('sandbox'), // `sandbox` seems to be the default accepted address MAX_ITEMS: envNumber.default('10000'), // Maximum number of events that are buffered in memory. MAX_BYTES: envNumber.default('262144'), // Maximum size in bytes that the logs are buffered in memory. - TIMEOUT_MS: envNumber.default('1000'), // Maximum time (in milliseconds) that a batch is buffered. + // Maximum time (in milliseconds) Lambda buffers telemetry before it hands it to the extension; the extension waits for + // this hand-off at the end of every invocation, so Lambda's minimum keeps that wait short. Raise it to get fewer, larger + // hand-offs in long invocations that log more than 40 lines per second, at that much more time per invocation. + TIMEOUT_MS: envNumber.default('25'), RECEIVER_PORT: envNumber.default('4243'), // HTTP server receiving port // Better Stack source token; SOURCE_TOKEN is preferred, LOGTAIL_TOKEN is kept as a fallback. SOURCE_TOKEN: z.string().optional(), diff --git a/src/extension.test.ts b/src/extension.test.ts index 32951cc..0a56cf5 100644 --- a/src/extension.test.ts +++ b/src/extension.test.ts @@ -45,7 +45,7 @@ describe('telemetrySubscription', () => { AWS_LAMBDA_RUNTIME_TELEMETRY_API_VERSION: '2022-07-01', RECEIVER_ADDRESS: 'sandbox', RECEIVER_PORT: 4243, - TIMEOUT_MS: 1000, + TIMEOUT_MS: 25, MAX_BYTES: 262144, MAX_ITEMS: 10000, }); @@ -54,7 +54,7 @@ describe('telemetrySubscription', () => { schemaVersion: '2022-07-01', destination: { protocol: 'HTTP', URI: 'http://sandbox:4243' }, types: ['platform', 'function'], - buffering: { timeoutMs: 1000, maxBytes: 262144, maxItems: 10000 }, + buffering: { timeoutMs: 25, maxBytes: 262144, maxItems: 10000 }, }); }); });