Skip to content

Commit

Permalink
Fixing in review
Browse files Browse the repository at this point in the history
Adding sentry configuration
  • Loading branch information
MatheusBlanco committed Apr 18, 2021
1 parent da4f770 commit 3c0c0da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
},
"devDependencies": {
"@types/cors": "^2.8.10",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.11",
"@types/morgan": "^1.9.2",
"@types/html-pdf": "^2.2.0",
"@types/jest": "^26.0.20",
"@types/morgan": "^1.9.2",
"@types/node": "^8.0.29",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
Expand Down Expand Up @@ -47,13 +48,15 @@
},
"homepage": "https://github.com/Eccoar/2020.2-Eccoar_Reports#readme",
"dependencies": {
"@sentry/node": "^6.2.5",
"@sentry/tracing": "^6.2.5",
"aws-sdk": "2.878.0",
"cors": "^2.8.5",
"dotenv": "8.2.0",
"express": "^4.17.1",
"handlebars": "^4.7.7",
"html-pdf": "^2.2.0",
"image-to-base64": "^2.1.1",
"dotenv": "8.2.0",
"aws-sdk": "2.878.0",
"morgan": "^1.10.0"
},
"lint-staged": {
Expand Down
20 changes: 20 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
import * as express from 'express';
import routers from './routes';
import * as cors from 'cors';
import * as dotenv from 'dotenv';
import * as morgan from 'morgan';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import handleErrors from '@utils/ErrorHadler';
import { reqHandler, traceHandler, errHandler } from './utils/sentry';

const app = express();
const PORT = process.env.APP_PORT || 5000;

dotenv.config();
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({ app }),
new Tracing.Integrations.Mysql(),
],

tracesSampleRate: 1.0,
});

app.use(reqHandler);
app.use(traceHandler);
app.use(express.json());
app.use(cors());
app.use(morgan('combined'));
app.use(routers);
app.use(errHandler);
app.use(handleErrors);

app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
6 changes: 6 additions & 0 deletions src/utils/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Sentry from '@sentry/node';
import * as express from 'express';

export const reqHandler = Sentry.Handlers.requestHandler() as express.RequestHandler;
export const traceHandler = Sentry.Handlers.tracingHandler();
export const errHandler = Sentry.Handlers.errorHandler() as express.ErrorRequestHandler;

0 comments on commit 3c0c0da

Please sign in to comment.