-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[fastify 4] Request body is not captured with fastify integration #16090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey, are you running your app in esm or cjs mode? Did you make sure to follow the respective docs:
My best guess for this not working would be that instrumentation is not fully correct, then we may not be able to capture the request body. Could you enable |
Hello, thanks for your answer. Sentry.init({
dsn,
tracesSampleRate: tracesSampleRate ?? 0.1,
release: process.env.RELEASE_NAME,
}); This function is called before fastify is imported I tried, as you said, to enable First, the logs for sentry initialization :
and then the logs for an endpoint on which I don't see the body of my request.
Still can't see any body : |
Are you consuming the body yourself in your application? We capture request bodiues by patching |
We used to swallow most things when we try to capture request bodies of incoming requests in node. This can make it hard to debug this. This PR adds some log messages here: 1. Logs when we successfully patched `request.on` 2. Logs the errors that happen during patching ref #16090
Hello, Unfortunately, I won't be able to give you full visibility into the code. I do not consume the body directly, but I have multiple hooks, middlewares, etc. It may come from this. Here is a description of my fastify instantiation. this.fastifyServer.setValidatorCompiler(validatorCompiler);
this.fastifyServer.setSerializerCompiler(serializerCompiler);
if (this.options?.docs?.generateDocs) {
await this.fastifyServer.register(fastifySwagger, {
...this.options.docs.baseConfig,
transform: jsonSchemaTransform,
});
}
this.fastifyServer.withTypeProvider<ZodTypeProvider>();
await this.fastifyServer.register(cors, {});
if (this.options?.contentTypeParser?.urlEncoded) {
await this.fastifyServer.register(formBodyParser);
}
this.fastifyServer.decorateRequest<
| {
id: number;
email: string;
roles: string[];
}
| undefined
>('userAuthInfo', undefined);
this.fastifyServer.decorateRequest<
| {
body?: any;
query?: any;
params?: any;
}
| undefined
>('parsedData', undefined);
[...]
this.fastifyServer.addHook('onRequest', async (request, reply) => {
[...]
// Logger middleware
// Authmiddleware
});
await this.fastifyServer.register(async (multipartServer) => {
await multipartServer.register(fastifyMultipart, {
limits: {
fileSize: this.options?.multipartServer?.limits?.fileSize,
files: this.options?.multipartServer?.limits?.files,
},
});
this.fastifyMultipartSubServer = multipartServer;
}); Sorry for not being able to include more details. Every POST endpoint ends up not showing any "body" section on Sentry dashboard (even the simplest endpoint with nothing in it) |
I totally understand, I do not expect full visibility into the code, just maybe a related snippet 🙂 We have merged a PR that will go out with the next release that adds further debug logs around this to make this easier to debug. In the meanwhile, I think we have identified the underlying problem - fastify does not use |
Hello, Thanks a lot. Let me know when the fix is released, I'll give it a try ! |
A PR closing this issue has just been released 🚀This issue was referenced by PR #16105, which was included in the 9.14.0 release. |
It worked ! :) (I updated @sentry/node to 9.14.0) Thank you @mydea |
I have a hunch that not all frameworks call `req.on('end')` but may only do `req.on('close')` or whatever else and this is why we are not reliably capturing bodies. It should be safe to attach a `req.on('end')` handler, as that doesn't change any semantics AFAIK. Fixes #16090 --------- Co-authored-by: Francesco Gringl-Novy <[email protected]>
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
9.11.0
Framework Version
fastify 4.28.0
Link to Sentry event
No response
Reproduction Example/SDK Setup
Steps to Reproduce
I installed sentry with fastify 4, following the documentation :
In every one of my sentry issues, I do not have a "body block" telling me the body payload of the incoming HTTP request. I have the request URL, the request headers, but no body payload.
Expected Result
Having the body payload in my issues in the incoming http requests informations, along with headers , and url (of couse, I tested for POST, PUT... in which I know I have a body with data in it)
Actual Result
The text was updated successfully, but these errors were encountered: