@@ -75,6 +75,7 @@ const headerGetter: TextMapGetter<APIGatewayProxyEventHeaders> = {
7575
7676export const lambdaMaxInitInMilliseconds = 10_000 ;
7777const 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' ) ;
7879const 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 }
0 commit comments