forked from poooi/plugin-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry.es
64 lines (56 loc) · 1.62 KB
/
sentry.es
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// FIXME: poi's browser sentry could not start due to a bug, initialize sentry here
import * as Sentry from '@sentry/electron'
import { isString, includes, get, each, takeRight, split } from 'lodash'
import path from 'path'
export const init = ({ build, paths }) => {
const fromatRelative = url => {
if (url.startsWith('app://')) {
return url
}
let result = url
each(paths, parent => {
if (url.startsWith(parent)) {
const relative = path.relative(parent, url)
if (!relative.startsWith('..')) {
result = relative
return false // this terminates `each`
}
}
})
if (path.isAbsolute(result)) {
return takeRight(split(result, path.sep), 3).join(path.sep)
}
return result
}
Sentry.init({
dsn: 'https://[email protected]/1250935',
beforeSend(event) {
if (
includes(
get(event, 'exception.mechanism.data.message'),
'React is running in production mode',
)
) {
return null
}
each(get(event, 'exception.values'), value => {
each(get(value, 'stacktrace.frames'), frame => {
if (frame.filename) {
frame.filename = fromatRelative(frame.filename)
}
})
})
// console.log(util.inspect(event, { depth: null }))
return event
},
beforeBreadcrumb(breadcrumb) {
if (breadcrumb.category === 'console') {
return null
}
return breadcrumb
},
})
Sentry.configureScope(scope => {
scope.setTag('build', isString(build) ? build.substring(0, 8) : 'DEV')
})
}