Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit f583d61

Browse files
committed
docker-compose with sentry
1 parent 38b7c0b commit f583d61

10 files changed

+266
-27
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SENTRY_SECRET_KEY=sc5+tmo)g%k8^(ms^nc5h@w+)6&6+8v845-j*ojk!p%hj+t#ip

api/package-lock.json

+136-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@appliedblockchain/mantle": "^1.0.10",
5353
"@appliedblockchain/store-contract-artefacts": "^0.3.0",
5454
"@koa/cors": "^2.2.1",
55+
"@sentry/node": "^4.3.0",
5556
"bunyan": "^1.8.12",
5657
"config": "^1.30.0",
5758
"koa": "^2.5.1",

api/src/api/Error/getError.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const handler = async () => {
2+
throw new Error('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.')
3+
}
4+
5+
module.exports = {
6+
method: 'get',
7+
path: '/error',
8+
handler
9+
}

api/src/middleware/error-handler.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
const logger = require('../logger')
2+
const Sentry = require('@sentry/node')
3+
const dsn = process.env.SENTRY_DSN || ''
4+
5+
if (dsn) {
6+
Sentry.init({ dsn: dsn })
7+
}
28

39
module.exports = async (ctx, next) => {
410
try {
511
await next()
612
} catch (err) {
13+
if (dsn) {
14+
Sentry.captureException(err, (sentryError, eventId) => {
15+
console.log(`Reported error ${eventId}`)
16+
})
17+
}
718
ctx.status = err.statusCode || 500
819
ctx.body = err.toJSON ? err.toJSON() : { message: err.message, ...err }
9-
1020
logger.error('Error in request', err)
1121
}
1222
}

api/src/router.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const koaRouter = require('koa-joi-router')
44
const configureDocs = require('./api/docs-config')
55
const rootRoute = require('./api/root')
66
const notes = require('./api/notes')
7+
const error = require('./api/Error/getError')
78
const { API_PREFIX } = require('./constants')
89

9-
const routes = [ ...rootRoute, ...notes ]
10+
const routes = [ ...rootRoute, ...notes, error ]
1011

1112
const router = koaRouter()
1213

docker-compose.with-sentry.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: "3.6"
2+
x-sentry-defaults: &sentry-defaults
3+
restart: unless-stopped
4+
build:
5+
context: ./sentry
6+
dockerfile: Dockerfile
7+
depends_on:
8+
- redis
9+
- postgres
10+
- memcached
11+
- smtp
12+
env_file: .env
13+
environment:
14+
SENTRY_MEMCACHED_HOST: memcached
15+
SENTRY_REDIS_HOST: redis
16+
SENTRY_POSTGRES_HOST: postgres
17+
SENTRY_EMAIL_HOST: smtp
18+
networks:
19+
- main
20+
volumes:
21+
- sentry-data:/var/lib/sentry/files
22+
23+
services:
24+
smtp:
25+
restart: unless-stopped
26+
image: tianon/exim4
27+
networks:
28+
- main
29+
30+
memcached:
31+
restart: unless-stopped
32+
image: memcached:1.4
33+
networks:
34+
- main
35+
36+
postgres:
37+
restart: unless-stopped
38+
image: postgres:9.5
39+
volumes:
40+
- sentry-postgres:/var/lib/postgresql/data
41+
networks:
42+
- main
43+
44+
sentry-web:
45+
<<: *sentry-defaults
46+
47+
ports:
48+
- '9000:9000'
49+
50+
sentry-cron:
51+
<<: *sentry-defaults
52+
command: run cron
53+
54+
sentry-worker:
55+
<<: *sentry-defaults
56+
command: run worker
57+
58+
volumes:
59+
sentry-data:
60+
external: true
61+
sentry-postgres:
62+
external: true

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
environment:
1717
- NODE_ENV=staging
1818
- PROVIDER=http://parity1:8545
19+
- SENTRY_DSN=http://6f20a6d7d8154e1f93593c634f943f7d@sentry-web:9000/3
1920
networks:
2021
- main
2122
ports:
@@ -46,6 +47,7 @@ services:
4647
- static
4748
deploy:
4849
<<: *deploy_defaults
50+
restart: unless-stopped
4951

5052
redis:
5153
image: redis

sentry/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM sentry:9.0-onbuild

0 commit comments

Comments
 (0)