Is there a way to capture the POST request body in Sentry.io when any request fails?
I am using @sentry/react
and "@sentry/tracing
version ^7.16.0
const onSubmit = async ({foo, bar}: IForm) => {
try {
await fetch(
`http://localhost:3001/v1/test`,
{
method: "POST",
body: JSON.stringify({
foo,
bar,
}),
headers: { "Content-Type": "application/json" },
}
);
} catch (err) {
Sentry.captureException(err);
}
}
It looks like the entire body is skipped from tracking in Sentry at all:
Sentry.init({
dsn: process.env.REACT_APP_SENTRY_DSN,
environment: process.env.REACT_APP_SENTRY_ENV,
integrations: [new BrowserTracing()],
tracesSampleRate: 1.0,
// Filtering important sensitive data before sending to Sentry.io
beforeBreadcrumb(breadcrumb, hint) {
console.log('beforeBreadcrumb breadcrumb: ', breadcrumb) // no post request body here
console.log('beforeBreadcrumb hint: ', hint) // no post request body here as well
return breadcrumb;
},
beforeSend(event, hint) {
console.log("beforeSend hint: ", hint); // no post request body here
console.log("beforeSend event: ", event); // no post request body here as well
return event;
},
})
And of course, there is no request body(foo/bar object) in the Sentry dashboard.
Is there any way to always add the POST request body/payload to each failed request exception?
Of course, I can add breadcrumbs before sending the request, but it would be nice to have this working by default.