Repository navigation
Closed as duplicate
Labels
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/aws-serverless
SDK Version
8.15.0
Framework Version
No response
Link to Sentry event
No response
SDK Setup/Reproduction Example
Sentry.init({ dsn: process.env.SENTRY_DSN });
Steps to Reproduce
- Define an AWS Lambda running with the Node 20.x runtime & configure the SENTRY_DSN env variable:
import * as Sentry from "@sentry/aws-serverless";
Sentry.init({ dsn: process.env.SENTRY_DSN });
// awslambda.streamifyResponse is patched into the global object by the lambda runtime
// https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
export const handler = Sentry.wrapHandler(
awslambda.streamifyResponse(async function (event, responseStream, _context) {
responseStream.write("hello");
responseStream.end();
})
);- Make a request (any payload)
- Check Lambda logs for error
Expected Result
Code should execute identically as if there had been no Sentry.wrapHandler (returning "hello")
Actual Result
Error logs from code above:
2024-07-09T00:38:31.701Z a203c0fb-7d33-4a3f-b5af-f76ed67423e6 ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "responseStream.write is not a function",
"stack": [
"TypeError: responseStream.write is not a function",
" at file:///var/task/index.js:299031:20",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async processResult (file:///var/task/index.js:10:14)"
]
}
My guess is that wrapHandler wasn't written to detect the streaming Lambda handler which takes different arguments than the default handler.
The Sentry docs have this snippet:
exports.handler = Sentry.wrapHandler(async (event, context) => {
// Your handler code
});...but the AWS streaming handler expects the second argument to be responseStream (not context)
Reacted by Leonie
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
chargome commentedon Jul 9, 2024
Hey @zmillman, thanks for reaching out. Currently our
wrapHandlerfunction does not supportstreamifyResponse. If you still want to usewrapHandlermake sure you pass a function that takes the correct arguments.We will put this issue onto our backlog to support
streamifyResponse.JQuezada0 commentedon Jul 24, 2024
Ran into this as well, although the error message was different
Here's an example workaround that worked for me.
You can "trick" the
wrapHandlerfunction and then pass the actual 3 arguments needed for streaming inside.Lms24 commentedon Jul 25, 2024
Hey @JQuezada0 thanks for posting this workaround. For the time being, this is how we recommend using the wrapper with
streamifyResponse.Note: If anyone coming across this issue is using our AWS Lambda layer and relied on its auto-wrapping capabilities, I suggest switching to the alternative layer usage which gives you the freedom to apply our wrapper yourself as shown in the code snippet above.
heypiotr commentedon Mar 18, 2025
Just a friendly nudge, New Relic beat you to it 😉 newrelic/node-newrelic#2901
chargome commentedon Mar 18, 2025
@andreiborza can I put this on your radar 👀
andreiborza commentedon Mar 21, 2025
I created a tracking issue for this: #15774. Please follow that issue for updates, I will close this one.