Skip to content

Commit e2903bf

Browse files
committed
tweaks
1 parent 135dde7 commit e2903bf

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const headerGetter: TextMapGetter<APIGatewayProxyEventHeaders> = {
7575

7676
export const lambdaMaxInitInMilliseconds = 10_000;
7777
const AWS_HANDLER_STREAMING_SYMBOL = Symbol.for('aws.lambda.runtime.handler.streaming');
78+
const AWS_HANDLER_HIGHWATERMARK_SYMBOL = Symbol.for('aws.lambda.runtime.handler.streaming.highWaterMark');
7879
const AWS_HANDLER_STREAMING_RESPONSE = 'response';
7980

8081
/**
@@ -106,11 +107,14 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
106107

107108
// Provide a temporary awslambda polyfill for CommonJS modules during loading
108109
// This prevents ReferenceError when modules use awslambda.streamifyResponse at load time
110+
// taken from https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/UserFunction.js#L205C7-L211C9
109111
if (typeof globalThis.awslambda === 'undefined') {
110112
(globalThis as any).awslambda = {
111-
streamifyResponse: (handler: any) => {
112-
// Add the streaming symbols that the instrumentation looks for
113+
streamifyResponse: (handler: any, options: any) => {
113114
handler[AWS_HANDLER_STREAMING_SYMBOL] = AWS_HANDLER_STREAMING_RESPONSE;
115+
if (typeof options?.highWaterMark === 'number') {
116+
handler[AWS_HANDLER_HIGHWATERMARK_SYMBOL] = parseInt(options.highWaterMark);
117+
}
114118
return handler;
115119
},
116120
};
@@ -208,11 +212,12 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
208212
const patchedHandler = this._getPatchHandler(original, handlerLoadStartTime);
209213

210214
// Streaming handlers have special symbols that we need to copy over to the patched handler.
211-
for (const symbol of Object.getOwnPropertySymbols(original)) {
212-
(patchedHandler as unknown as Record<symbol, unknown>)[symbol] = (
213-
original as unknown as Record<symbol, unknown>
214-
)[symbol];
215-
}
215+
(patchedHandler as unknown as Record<symbol, unknown>)[AWS_HANDLER_STREAMING_SYMBOL] = (
216+
original as unknown as Record<symbol, unknown>
217+
)[AWS_HANDLER_STREAMING_SYMBOL];
218+
(patchedHandler as unknown as Record<symbol, unknown>)[AWS_HANDLER_HIGHWATERMARK_SYMBOL] = (
219+
original as unknown as Record<symbol, unknown>
220+
)[AWS_HANDLER_HIGHWATERMARK_SYMBOL];
216221

217222
return wrapHandler(patchedHandler) as T;
218223
}

packages/aws-serverless/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function setupTimeoutWatning(context: Context, options: WrapperOptions): NodeJS.
133133
return undefined;
134134
}
135135

136-
export const AWS_HANDLER_HIGHWATERMARK_SYMBOL = Symbol.for('aws.lambda.runtime.handler.highWaterMark');
136+
export const AWS_HANDLER_HIGHWATERMARK_SYMBOL = Symbol.for('aws.lambda.runtime.handler.streaming.highWaterMark');
137137
export const AWS_HANDLER_STREAMING_SYMBOL = Symbol.for('aws.lambda.runtime.handler.streaming');
138138
export const AWS_HANDLER_STREAMING_RESPONSE = 'response';
139139

0 commit comments

Comments
 (0)