Asayer Tracker Fetch plugin
Tracker plugin to support tracking of the fetch
requests payload.
Additionally it populates the requests with sessionID
header for backend logging.
Installation
npm i @asayerio/tracker-fetch
Usage
Initialize the @asayerio/tracker
package as usual and load the plugin into it.
Then you can use the provided fetch
method from the plugin instead of built-in.
import Tracker from '@asayerio/tracker';
import trackerFetch from '@asayerio/tracker-fetch';
const tracker = new Tracker({
projectID: PROJECT_ID,
});
tracker.start();
export const fetch = tracker.use(trackerFetch({
sessionTokenHeader: 'X-Session-ID',
failuresOnly: true
}));
fetch('https://api.asayer.io/').then(response => console.log(response.json()));
In case you use Asayer integrations (sentry, bugsnag or others), you can use sessionTokenHeader
option to specify the header name. This header will be appended automatically to the each fetch request and will contain Asayer session identificator value.
Set failuresOnly
option to true
if you want to record only requests with the status code >= 400.