-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentry.js
44 lines (39 loc) · 1.02 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
const Sentry = require('@sentry/node')
const log = require('@miroculus/log')
const { SENTRY_URL, BUILD_NUMBER } = process.env
if (SENTRY_URL) {
Sentry.init({
dsn: SENTRY_URL,
release: BUILD_NUMBER
})
log.on('log', ({ level, args }) => {
switch (level) {
case 'critical': {
const [err] = args
Sentry.withScope((scope) => {
scope.setLevel('fatal')
Sentry.captureException(err)
})
break
}
case 'error': {
const [err] = args
Sentry.captureException(err)
break
}
case 'warn': {
const [msg, data] = args
// log.warn allows you to post extra data to be sended to sentry
const extra = typeof data === 'string' || typeof data === 'number'
? { data }
: data
Sentry.withScope((scope) => {
scope.setLevel('warning')
if (data !== undefined) scope.setExtra('data', extra)
Sentry.captureMessage(msg)
})
break
}
}
})
}