diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-01-10 13:19:05 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-01-10 13:20:37 +1100 |
commit | 2f065e6b3793f2c2d4ab196a341cf23efb721011 (patch) | |
tree | 8966b0ec65d611d7b3a129e16d3276b58344ba44 /src/bundle/Server.ts | |
parent | Add error handler for individual gateway sockets (diff) | |
download | server-2f065e6b3793f2c2d4ab196a341cf23efb721011.tar.xz |
Move sentry init to util. use sentry in each module, not just bundle
Diffstat (limited to 'src/bundle/Server.ts')
-rw-r--r-- | src/bundle/Server.ts | 78 |
1 files changed, 3 insertions, 75 deletions
diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts index e6f8d17c..abd05e1f 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts @@ -7,10 +7,7 @@ import * as Gateway from "@fosscord/gateway"; import { CDNServer } from "@fosscord/cdn"; import express from "express"; import { green, bold, yellow } from "picocolors"; -import { Config, initDatabase } from "@fosscord/util"; -import * as Sentry from "@sentry/node"; -import * as Tracing from "@sentry/tracing"; -import * as Integrations from "@sentry/integrations"; +import { Config, initDatabase, Sentry } from "@fosscord/util"; const app = express(); const server = http.createServer(); @@ -30,81 +27,12 @@ process.on("SIGTERM", async () => { async function main() { await initDatabase(); await Config.init(); - - //Sentry - if (Config.get().sentry.enabled) { - console.log( - `[Bundle] ${yellow( - "You are using Sentry! This may slightly impact performance on large loads!", - )}`, - ); - Sentry.init({ - dsn: Config.get().sentry.endpoint, - integrations: [ - new Sentry.Integrations.Http({ tracing: true }), - new Tracing.Integrations.Express({ app }), - new Tracing.Integrations.Mysql(), - new Integrations.RewriteFrames({ - root: __dirname, - }), - ], - tracesSampleRate: Config.get().sentry.traceSampleRate, - environment: Config.get().sentry.environment, - }); - - Sentry.addGlobalEventProcessor((event, hint) => { - if (event.transaction) { - // Rewrite things that look like IDs to `:id` for sentry - event.transaction = event.transaction - .split("/") - .map((x) => (!parseInt(x) ? x : ":id")) - .join("/"); - } - - // TODO: does this even do anything? - delete event.request?.cookies; - if (event.request?.headers) { - delete event.request.headers["X-Real-Ip"]; - delete event.request.headers["X-Forwarded-For"]; - delete event.request.headers["X-Forwarded-Host"]; - delete event.request.headers["X-Super-Properties"]; - } - - if (event.breadcrumbs) { - event.breadcrumbs = event.breadcrumbs.filter((x) => { - // Filter breadcrumbs that we don't care about - if (x.message?.includes("identified as")) return false; - if (x.message?.includes("[WebSocket] closed")) return false; - if ( - x.message?.includes( - "Got Resume -> cancel not implemented", - ) - ) - return false; - if (x.message?.includes("[Gateway] New connection from")) - return false; - - return true; - }); - } - - return event; - }); - - app.use(Sentry.Handlers.requestHandler()); - app.use(Sentry.Handlers.tracingHandler()); - } + await Sentry.init(app); server.listen(port); await Promise.all([api.start(), cdn.start(), gateway.start()]); - if (Config.get().sentry.enabled) { - app.use(Sentry.Handlers.errorHandler()); - app.use(function onError(err: any, req: any, res: any, next: any) { - res.statusCode = 500; - res.end(res.sentry + "\n"); - }); - } + Sentry.errorHandler(app); console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`); } |