-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from dataforgoodfr/chore/D4G-259-track-server…
…-error-in-sentry chore(ogre-server): Log errors to sentry
- Loading branch information
Showing
6 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as Sentry from "@sentry/node"; | ||
import * as Tracing from "@sentry/tracing"; | ||
import { Request, Response, Router } from "express"; | ||
import { getUserRequesting } from "../lib/express"; | ||
|
||
export { initErrorTracer, traceError, traceRequests }; | ||
|
||
const initErrorTracer = (app: Router) => { | ||
Sentry.init({ | ||
dsn: process.env.SENTRY_DSN, | ||
environment: process.env.SENTRY_ENV || "development", | ||
integrations: [ | ||
new Sentry.Integrations.Http({ tracing: true }), | ||
new Tracing.Integrations.Express({ app }), | ||
], | ||
// TODO: adapt value in production. | ||
tracesSampleRate: 1.0, | ||
}); | ||
}; | ||
|
||
const traceRequests = (app: Router) => { | ||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
}; | ||
|
||
const traceError = (err: Error, req: Request, res: Response) => { | ||
const data = Sentry.extractRequestData(req); | ||
const user = getUserRequesting(res); | ||
Sentry.captureException(err, { | ||
user: { | ||
id: user?.id?.toString(), | ||
}, | ||
contexts: data, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters