Sentry Integration

Cohere's Sentry integration allows you to attach Cohere Replay sessions directly to Sentry reports.

In order to use the Sentry integration, you must be on a Pro plan or have the Cohere Replay add-on. To upgrade, return to your dashboard and go to Settings → Add Cohere Replay.

Cohere-Sentry NPM Module

First, make sure you're using @sentry/browser >=1.0.0 and cohere-js >=1.0.19. Next, install the NPM module:

npm install --save cohere-sentry

Finally, update your Sentry initialization:

import * as Sentry from '@sentry/browser';
import Cohere from 'cohere-js';
import CohereSentry from 'cohere-sentry';
Cohere.init('INSERT_COHERE_API_KEY_HERE');
Sentry.init({
dsn: 'INSERT_SENTRY_DSN_HERE',
integrations: [ new CohereSentry(), ],
// ...
});

Manual Integration

If you're unable to use the NPM module, you can manually integrate into Sentry. Copy the following code and paste it right after you initialize Sentry and Cohere:

const sessionUrlListener = (sessionUrl) => {
Sentry.configureScope((scope) => {
scope.addEventProcessor((event) => {
event.contexts = {
...event.contexts,
Cohere: {
"Cohere Session URL": `${sessionUrl}${
event.timestamp ? `?ts=${event.timestamp * 1000}` : ""
}`,
},
};
return event;
});
});
}
Cohere.addSessionUrlListener(sessionUrlListener);
// If calling the above code multiple times (e.g. React useEffect), don't forget to clean up!
// Cohere.removeSessionUrlListener(sessionUrlListener);

Don't add any other Sentry configuration in the session URL listener, as the listener will not run if a session URL is not found, and the listener will run every time a new session URL is generated. To avoid any unexpected behavior, put unrelated Sentry configuration outside the listener.