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:
1
npm install --save cohere-sentry
Copied!
Finally, update your Sentry initialization:
1
import * as Sentry from '@sentry/browser';
2
import Cohere from 'cohere-js';
3
import CohereSentry from 'cohere-sentry';
4
5
Cohere.init('INSERT_COHERE_API_KEY_HERE');
6
7
Sentry.init({
8
dsn: 'INSERT_SENTRY_DSN_HERE',
9
integrations: [ new CohereSentry(), ],
10
// ...
11
});
Copied!

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:
1
const sessionUrlListener = (sessionUrl) => {
2
Sentry.configureScope((scope) => {
3
scope.addEventProcessor((event) => {
4
event.contexts = {
5
...event.contexts,
6
Cohere: {
7
"Cohere Session URL": `${sessionUrl}${
8
event.timestamp ? `?ts=${event.timestamp * 1000}` : ""
9
}`,
10
},
11
};
12
return event;
13
});
14
});
15
}
16
17
Cohere.addSessionUrlListener(sessionUrlListener);
18
19
// If calling the above code multiple times (e.g. React useEffect), don't forget to clean up!
20
// Cohere.removeSessionUrlListener(sessionUrlListener);
Copied!
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.
Last modified 2mo ago