-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry.js
45 lines (40 loc) · 1.27 KB
/
sentry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as Sentry from '@sentry/browser'
import { Integrations } from '@sentry/tracing'
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [new Integrations.BrowserTracing()],
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
})
} else {
console.log('Sentry is turned off.')
}
export function captureMessage(message, data) {
// Sentry doesn't provide the option of seeing the full message if it's long
// and Elm decode errors that log the entire data structure are very long
// and have the useful bit at the very end, which is truncated by Sentry
const truncatedData =
data.length < 2000
? data
: data.slice(0, 1000) + '\n...TRUNCATED...\n' + data.slice(-1000)
if (process.env.SENTRY_DSN) {
console.log('The following information has been reported:')
console.log(truncatedData)
Sentry.captureEvent({
message,
breadcrumbs: [
{
message: truncatedData,
},
],
})
} else {
console.log(
'Error reporting is currently turned off. Here is what would have been reported:',
)
console.log(truncatedData)
}
}