Skip to content

Commit 0213633

Browse files
committedJan 21, 2020
setup Sentry
·
v0.19.40.2.0
1 parent e2e100a commit 0213633

File tree

5 files changed

+144
-961
lines changed

5 files changed

+144
-961
lines changed
 

‎package-lock.json

Lines changed: 113 additions & 961 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"watch": "tsc -watch -p ./"
3232
},
3333
"dependencies": {
34+
"@sentry/node": "^5.11.0",
3435
"chokidar": "^3.3.0",
3536
"dotenv": "^8.2.0",
3637
"jsdom": "^15.2.1"

‎src/environment.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ require('dotenv').config({
33
})
44

55
interface Environment {
6+
VERSION: string
7+
NODE_ENV: string
68
LOG: boolean
79
}
810

911
const environment: Environment = {
12+
VERSION: process.env.VERSION || 'unknown',
13+
NODE_ENV: process.env.NODE_ENV || 'production',
1014
LOG: (process.env.LOG || '').toLowerCase() === 'true',
1115
}
1216

‎src/services/sentry/init.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as sentry from '@sentry/node'
2+
import environment from '../../environment'
3+
4+
sentry.init({
5+
dsn: 'https://df4a6ae19e8b44ed9a87ae4432dab9df@sentry.io/1889368',
6+
environment: environment.NODE_ENV,
7+
})

‎src/services/sentry/onError.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as sentry from '@sentry/node'
2+
import { Scope } from '@sentry/hub'
3+
import environment from '../../environment'
4+
5+
const onError = error => {
6+
// set user scope https://docs.sentry.io/enriching-error-data/scopes/?platform=node
7+
sentry.withScope((scope: Scope) => {
8+
scope.setTag('VERSION', environment.VERSION)
9+
// if (user) {
10+
// scope.setUser({
11+
// id: user.id,
12+
// email: user.email || 'unknown',
13+
// })
14+
// }
15+
sentry.captureException(error)
16+
})
17+
}
18+
19+
export default onError

0 commit comments

Comments
 (0)
Please sign in to comment.