Skip to content

Commit ae73486

Browse files
committed
refactor: simplify runtime detection and update README example
- Refactor getNodeRuntimeVersion() to isSupportingCallbacks() returning boolean - Default to false (no callbacks) when AWS_EXECUTION_ENV is not set - Update README example to use ESM syntax for Promise-based handler
1 parent 3f03df1 commit ae73486

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/instrumentation-aws-lambda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ exports.handler = function(event, context, callback) {
4242
};
4343

4444
// Promise-based handler (all Node.js versions)
45-
exports.handler = async function(event, context) {
45+
export const handler = async (event, context) => {
4646
return 'ok';
4747
};
4848
```

packages/instrumentation-aws-lambda/src/instrumentation.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,23 @@ export const AWS_HANDLER_STREAMING_SYMBOL = Symbol.for(
7272
export const AWS_HANDLER_STREAMING_RESPONSE = 'response';
7373

7474
/**
75-
* Detects the Node.js runtime version from AWS_EXECUTION_ENV environment variable.
76-
* Returns the major version number (e.g., 24, 22, 20) or null if not detected.
75+
* Determines if callback-based handlers are supported based on the Node.js runtime version.
76+
* Returns true if callbacks are supported (Node.js < 24).
77+
* Returns false if AWS_EXECUTION_ENV is not set or doesn't match the expected format.
7778
*/
78-
function getNodeRuntimeVersion(): number | null {
79+
function isSupportingCallbacks(): boolean {
7980
const executionEnv = process.env.AWS_EXECUTION_ENV;
8081
if (!executionEnv) {
81-
return null;
82+
return false;
8283
}
8384

8485
// AWS_EXECUTION_ENV format: AWS_Lambda_nodejs24.x, AWS_Lambda_nodejs22.x, etc.
8586
const match = executionEnv.match(/AWS_Lambda_nodejs(\d+)\./);
8687
if (match && match[1]) {
87-
return parseInt(match[1], 10);
88+
return parseInt(match[1], 10) < 24;
8889
}
8990

90-
return null;
91+
return false;
9192
}
9293

9394
export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstrumentationConfig> {
@@ -291,9 +292,8 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
291292
};
292293
}
293294

294-
// Determine runtime version to decide whether to support callbacks
295-
const nodeVersion = getNodeRuntimeVersion();
296-
const supportsCallbacks = nodeVersion === null || nodeVersion < 24;
295+
// Determine whether to support callbacks based on runtime version
296+
const supportsCallbacks = isSupportingCallbacks();
297297

298298
if (supportsCallbacks) {
299299
// Node.js 22 and lower: Support callback-based handlers for backward compatibility

0 commit comments

Comments
 (0)