Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send payload data with POST/PUT/PATCH requests to Sentry.io

Tags:

angular

sentry

I'm trying to add the payload data to the breadcrumbs sent to Sentry.io.

It just looks like this.

enter image description here

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.

like image 974
Snæbjørn Avatar asked Sep 09 '26 00:09

Snæbjørn


1 Answers

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.

like image 192
Lucas Quinteiro Avatar answered Sep 10 '26 15:09

Lucas Quinteiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!