Skip to content

Commit

Permalink
Merge pull request #7 from Eccoar/156_sentry
Browse files Browse the repository at this point in the history
Solve #156 Configuração Sentry
  • Loading branch information
Victor-Buendia authored Apr 27, 2021
2 parents 0c5196c + 3c0c0da commit 0eae7b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@types/cors": "^2.8.10",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.11",
"@types/html-pdf": "^2.2.0",
"@types/jest": "^26.0.20",
Expand Down Expand Up @@ -49,13 +50,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 0eae7b3

Please sign in to comment.