2021-09-21 12:47:14 +02:00
|
|
|
import * as Sentry from "@sentry/browser"
|
|
|
|
|
|
|
|
export default class SentryClient {
|
|
|
|
constructor(dsn) {
|
|
|
|
this.dsn = dsn
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
if (this.dsn) {
|
|
|
|
Sentry.init({ dsn: this.dsn })
|
|
|
|
|
|
|
|
this.initalised = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 21:47:04 +02:00
|
|
|
/**
|
|
|
|
* Capture an exception and send it to sentry.
|
|
|
|
* @param {Error} err - JS error object
|
|
|
|
*/
|
2021-09-21 12:47:14 +02:00
|
|
|
captureException(err) {
|
|
|
|
if (!this.initalised) return
|
|
|
|
|
|
|
|
Sentry.captureException(err)
|
|
|
|
}
|
|
|
|
|
2021-09-21 21:47:04 +02:00
|
|
|
/**
|
|
|
|
* Identify user in sentry.
|
|
|
|
* @param {String} id - Unique user id
|
|
|
|
*/
|
2021-09-21 12:47:14 +02:00
|
|
|
identify(id) {
|
2021-09-21 21:21:15 +02:00
|
|
|
if (!this.initalised) return
|
|
|
|
|
2021-09-21 12:47:14 +02:00
|
|
|
Sentry.configureScope(scope => {
|
|
|
|
scope.setUser({ id })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|