I'm trying to add the payload data to the breadcrumbs sent to Sentry.io.
It just looks like this.
I found out how to add the response.
const sentryConfig: BrowserOptions = {
beforeBreadcrumb: (breadcrumb, hint) => {
if (breadcrumb.category === 'xhr') {
// hint.xhr is a whole XHR object that you can use to modify breadcrumb
breadcrumb.data = (hint.xhr as XMLHttpRequest).response;
}
return breadcrumb;
}
};
But I cannot seem to find a way to add the payload. XMLHttpRequest
doesn't have this info.
It is possible to get the body (payload data) from your xhr this way:
beforeBreadcrumb: (breadcrumb, hint) => {
if (breadcrumb.category === 'xhr') {
const data = {
requestBody: hint.xhr.__sentry_xhr__.body,
response: hint.xhr.response,
responseUrl: hint.xhr.responseURL
}
return { ...breadcrumb, data }
}
return breadcrumb
}
This is the PR where it was added.