UNPKG

1.28 kBPlain TextView Raw
1import type Raven from 'raven'
2
3import os from 'os'
4
5import {
6 log,
7} from './config'
8import {
9 VERSION,
10 GIT_COMMIT_HASH,
11} from './version'
12
13let raven: typeof Raven
14
15function getRavenDsn (): undefined | string {
16 // const RAVEN_DSN = 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672'
17 const dsn = process.env['WECHATY_RAVEN_DSN']
18 return dsn
19}
20
21function enableRaven (dsn: string):void {
22 /**
23 * Raven.io
24 */
25 const ravenOptions = {
26 release: VERSION,
27 tags: {
28 git_commit: GIT_COMMIT_HASH,
29 platform: process.env['WECHATY_DOCKER']
30 ? 'docker'
31 : os.platform(),
32 },
33 }
34
35 raven.disableConsoleAlerts()
36 raven
37 .config(dsn, ravenOptions)
38 .install()
39}
40function init () {
41 try {
42 raven = require('raven')
43 } catch (e) {
44 // It's ok when there's no raven installed
45 log.verbose('Wechaty', 'init() require("raven") not succeed, skipped.')
46 return
47 }
48
49 const dsn = getRavenDsn()
50 if (!dsn) {
51 log.verbose('Wechaty', 'init() getRavenDsn() return undefined, skipped.')
52 return
53 }
54
55 enableRaven(dsn)
56}
57
58function captureException (e: Error) {
59 if (raven) {
60 raven.captureException(e)
61 }
62}
63
64init()
65
66export {
67 captureException,
68}