Skip to content

AWS Lambda Instrumentation causes lambda failures when using streaming response #2827

@thpierce

Description

@thpierce

What version of OpenTelemetry are you using?

1.9.0 (api), 2.0.0 (core)

What version of Node are you using?

Node.js 22.x

What did you do?

  • Create new Lambda function using Node.js 22.x with function body:
export const handler = awslambda.streamifyResponse(
  async (event, responseStream, _context) => {
    console.log(event)
    console.log(responseStream)
    console.log(_context)
    responseStream.write('test payload');
    responseStream.end();
  }
)

What did you expect to see?

Expected instrumentation to work.

What did you see instead?

Instrumentation caused my lambda to fail.

Additional context

The problem appears to be opentelemetry-instrumentation-aws-lambda. The instrumentation basically looks for any handler and replaces it with a patched handler that has 3 args: event, context, and callback. However, with streaming response lambdas the handler is streamifyReponse which needs 4 args: event, context, responseStream, and callback. So, responseStream is overwritten with callback and becomes unusable.

Two solutions:

  1. [Short term] Do not instrument if handler is a streamifyReponse - Callout, this means streaming response lambdas will not be supported
  2. [Long term] Properly instrument streamifyResponse, fully supporting both "normal" and streaming response lambdas.

Let me know if I should cut a separate issue for 2, above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:instrumentation-aws-lambdapriority:p1Bugs which cause problems in end-user applications such as crashes, data inconsistencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions