Skip to content

Commit 1a7e6ac

Browse files
authored
feat(sdk): add SDK version to AWS Lambda client user agent (#440)
Include SDK version in the Lambda client's customUserAgent to enable better debugging visibility. This allows cross-referencing SDK versions with API request IDs when troubleshooting issues. The version and package name are injected at build time by Rollup from package.json using environment variable replacement. Changes: - Add NPM_PACKAGE_NAME to Rollup replace plugin - Use process.env.NPM_PACKAGE_NAME and process.env.NPM_PACKAGE_VERSION - Configure LambdaClient with customUserAgent including SDK name and version - Update tests to use process.env constants - Rollup replaces these at build time with actual values from package.json
1 parent 2b541fc commit 1a7e6ac

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

packages/aws-durable-execution-sdk-js/src/durable-execution-api-client/durable-execution-api-client-caching.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LambdaClient } from "@aws-sdk/client-lambda";
22
import { DurableExecutionApiClient } from "./durable-execution-api-client";
3+
import { SDK_NAME, SDK_VERSION } from "../utils/constants/version";
34

45
// Mock the LambdaClient
56
jest.mock("@aws-sdk/client-lambda", () => {
@@ -49,6 +50,7 @@ describe("DurableExecutionApiClient Caching", () => {
4950

5051
// Verify the constructor was called with correct configuration
5152
expect(LambdaClient).toHaveBeenCalledWith({
53+
customUserAgent: [[SDK_NAME, SDK_VERSION]],
5254
requestHandler: {
5355
connectionTimeout: 5000,
5456
socketTimeout: 50000,

packages/aws-durable-execution-sdk-js/src/durable-execution-api-client/durable-execution-api-client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { OperationSubType } from "../types";
1010
import { log } from "../utils/logger/logger";
1111
import { DurableExecutionApiClient } from "./durable-execution-api-client";
1212
import { DurableExecutionClient } from "../types/durable-execution";
13+
import { SDK_NAME, SDK_VERSION } from "../utils/constants/version";
1314

1415
// Mock the logger
1516
jest.mock("../utils/logger/logger", () => ({
@@ -46,6 +47,7 @@ describe("ApiStorage", () => {
4647

4748
// Verify that LambdaClient was constructed with the correct default configuration
4849
expect(LambdaClient).toHaveBeenCalledWith({
50+
customUserAgent: [[SDK_NAME, SDK_VERSION]],
4951
requestHandler: {
5052
connectionTimeout: 5000,
5153
socketTimeout: 50000,

packages/aws-durable-execution-sdk-js/src/durable-execution-api-client/durable-execution-api-client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { DurableExecutionClient } from "../types/durable-execution";
1111
import { log } from "../utils/logger/logger";
1212
import { DurableLogger } from "../types/durable-logger";
13+
import { SDK_NAME, SDK_VERSION } from "../utils/constants/version";
1314

1415
let defaultLambdaClient: LambdaClient | undefined;
1516

@@ -27,6 +28,7 @@ export class DurableExecutionApiClient implements DurableExecutionClient {
2728
if (!client) {
2829
if (!defaultLambdaClient) {
2930
defaultLambdaClient = new LambdaClient({
31+
customUserAgent: [[SDK_NAME, SDK_VERSION]],
3032
requestHandler: {
3133
connectionTimeout: 5000,
3234
socketTimeout: 50000,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* SDK metadata injected by Rollup at build time from package.json.
3+
*
4+
* At build time, Rollup replaces process.env.NPM_PACKAGE_NAME and
5+
* process.env.NPM_PACKAGE_VERSION with actual values from package.json.
6+
*
7+
* Defaults are provided for test environments where Rollup doesn't run
8+
* and process.env values are undefined.
9+
*
10+
* @internal
11+
*/
12+
export const SDK_NAME =
13+
process.env.NPM_PACKAGE_NAME || "@aws/durable-execution-sdk-js";
14+
export const SDK_VERSION = process.env.NPM_PACKAGE_VERSION || "0.0.0";

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function createBuildOptions(options, mode, packageJson) {
3434
"process.env.IS_ESM": JSON.stringify(mode === "esm"),
3535
"process.env.NODE_ENV": JSON.stringify("production"),
3636
"process.env.NPM_PACKAGE_VERSION": JSON.stringify(packageJson.version),
37+
"process.env.NPM_PACKAGE_NAME": JSON.stringify(packageJson.name),
3738
},
3839
}),
3940
];

0 commit comments

Comments
 (0)