From 0c3d8a792f9f17f2f28ad449cd8bc5c2a381c8d5 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 29 Sep 2025 21:28:06 +0200 Subject: [PATCH] Drop @sentry/node (Sentry support) - untested and unused --- package-lock.json | Bin 429971 -> 399252 bytes package.json | 1 - src/api/Server.ts | 4 - src/api/middlewares/Authentication.ts | 3 - src/api/util/handlers/Message.ts | 7 - src/bundle/Server.ts | 6 +- src/cdn/Server.ts | 4 - src/gateway/Server.ts | 2 - src/gateway/events/Message.ts | 25 +--- src/util/config/Config.ts | 2 - src/util/config/types/SentryConfiguration.ts | 27 ---- src/util/config/types/index.ts | 1 - src/util/util/Sentry.ts | 130 ------------------- src/util/util/index.ts | 1 - 14 files changed, 3 insertions(+), 210 deletions(-) delete mode 100644 src/util/config/types/SentryConfiguration.ts delete mode 100644 src/util/util/Sentry.ts diff --git a/package-lock.json b/package-lock.json index 301b0ff7789898efce9e6f9ec949f83bb6204938..ebe0fcab644758227ab50f952200306a8cdba8c7 100644 GIT binary patch delta 276 zcmbO{Uuw#Fi4CfZ%`S}FT^Jclg12v5$k@xd-EJ-81@`F=elfCbzj~appme&lKcmfb zfe@AQPtOrp~p4lqei z=WAk9+-_>Y8o)GNU_O)f^x0Odzo#20GHP#MW6kQq3t~c59>`#k-LB!u%FBol+#cY? zs)NLz4&-ZZKjaNnq`m#A59>tB?VcU1QjFWDceAcioW6DoEBE%;b*%TJxBum4o7M~f Dfbn3k delta 18445 zcmdsfd8{MneHh5cw>qqqwX%0thqc;6mqqc-!MW&2mWIdh9FjwF$RRB&9&(1m;gB=K znc<1lDgMq-ut9KhF7?ua}Q1&LdZ*@W!gUHr);DhJ`hlfN{g(496KLUo4e{_|P zDk@##CM`9CGqE;1VATl~PFKsUJW^n(Ey@N?L2z|I$Lv{k)avQHGg}BT2xS)YUNvSn zxGr9W)43E(=i?SL>YH-2O!fL!nVQjTGFpY7R zm#(ZGv10&`&zy*8&-G5EXBe9M_Wudp=YA>@M4mozu6MJ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hM)7K{ zz~pjC8y6@v$DtUEm!zCbXOeMUG?+wJvhZ}hL(+{-Y{rxMw#9^_f`l_@r&C5mj>$XC zFo6q1s+(`QZ@<@16F=^TvEbS32aM!f(B;bdiEZJ#5^bFlRx{9jS9nEJlI)1;z>ah+ zV+bnso!)9DNM3mn?>qj^o!hgs=Xb(i+=!mN(>GfEh3@Dty&r-g+?W3C26D|SxCUXY zKsE(axBCZrsOswlm@yLMBzo_3G)osu_bCOr)djPF}{k zD(Tay`{i`#jQc&eiz?V8`+e9*mA3nCXi)GRwG!1?z7a6euPK3XdzbBl64 zl}eQ>;Wu<&(~fw7McJCj5qmxysJaGZ%RmHq zh%n&0R}&j&FB||&Th(_j>b^4F_l=^qh66Wrp&ILg9vdawk;^gx%K0>;K~v%3xGWN#YG1BI z>r@^kN3nPuv1+Mk1u@CY1YRJmIo+XbqCS~W$?Uw*B`AcY9oR*7g3q|+&jdR=|95-y H. */ -import * as Sentry from "@sentry/node"; import { checkToken, Rights } from "@spacebar/util"; import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; @@ -108,8 +107,6 @@ export async function Authentication( if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401)); - Sentry.setUser({ id: req.user_id }); - try { const { decoded, user } = await checkToken(req.headers.authorization); diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 1422702d..8356ee61 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -16,7 +16,6 @@ along with this program. If not, see . */ -import * as Sentry from "@sentry/node"; import { EmbedHandlers } from "@spacebar/api"; import { Application, @@ -422,12 +421,6 @@ export async function postHandleMessage(message: Message) { } } catch (e) { console.error(`[Embeds] Error while generating embed for ${link}`, e); - Sentry.captureException(e, (scope) => { - scope.clear(); - scope.setContext("request", { url: link }); - return scope; - }); - continue; } } diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts index 8ef72750..e6fcd97e 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts @@ -28,7 +28,7 @@ import * as Webrtc from "@spacebar/webrtc"; import { CDNServer } from "@spacebar/cdn"; import express from "express"; import { green, bold } from "picocolors"; -import { Config, initDatabase, Sentry } from "@spacebar/util"; +import { Config, initDatabase } from "@spacebar/util"; const app = express(); const server = http.createServer(); @@ -53,13 +53,11 @@ process.on("SIGTERM", async () => { await api.stop(); await webrtc.stop(); server.close(); - Sentry.close(); }); async function main() { await initDatabase(); await Config.init(); - await Sentry.init(app); const logRequests = process.env["LOG_REQUESTS"] != undefined; if (logRequests) { @@ -89,8 +87,6 @@ async function main() { webrtc.start(), ]); - Sentry.errorHandler(app); - console.log(`[Server] ${green(`Listening on port ${bold(port)}`)}`); } diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts index 287b2950..062ae19e 100644 --- a/src/cdn/Server.ts +++ b/src/cdn/Server.ts @@ -22,7 +22,6 @@ import { Config, initDatabase, registerRoutes, - Sentry, } from "@spacebar/util"; import { CORS, BodyParser } from "@spacebar/api"; import path from "path"; @@ -45,7 +44,6 @@ export class CDNServer extends Server { await initDatabase(); await Config.init(); await this.cleanupSignaturesInDb(); - await Sentry.init(this.app); const logRequests = process.env["LOG_REQUESTS"] != undefined; if (logRequests) { @@ -123,8 +121,6 @@ export class CDNServer extends Server { ); this.log("verbose", "[Server] Route /guilds/banners registered"); - Sentry.errorHandler(this.app); - return super.start(); } diff --git a/src/gateway/Server.ts b/src/gateway/Server.ts index 94b4fbe9..79206e4a 100644 --- a/src/gateway/Server.ts +++ b/src/gateway/Server.ts @@ -24,7 +24,6 @@ import { Config, initDatabase, initEvent, - Sentry, } from "@spacebar/util"; import ws from "ws"; import { Connection } from "./events/Connection"; @@ -74,7 +73,6 @@ export class Server { await initDatabase(); await Config.init(); await initEvent(); - await Sentry.init(); // temporary fix await cleanupOnStartup(); diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts index 8ec9fc7d..01836906 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts @@ -16,7 +16,6 @@ along with this program. If not, see . */ -import * as Sentry from "@sentry/node"; import { CLOSECODES, OPCODES, Payload, WebSocket } from "@spacebar/gateway"; import { ErlpackType, PayloadSchema } from "@spacebar/util"; import fs from "fs/promises"; @@ -25,6 +24,7 @@ import path from "path"; import WS from "ws"; import OPCodeHandlers from "../opcodes"; import { check } from "../opcodes/instanceOf"; + const bigIntJson = BigIntJson({ storeAsString: true }); let erlpack: ErlpackType | null = null; @@ -89,29 +89,8 @@ export async function Message(this: WebSocket, buffer: WS.Data) { } try { - return await Sentry.startSpan( - // Emma [it/its]@Rory&: is this the right function to migrate to in v8? - { - op: "websocket.server", - name: `GATEWAY ${OPCODES[data.op]}`, - attributes: { - // this needs to be reworked :) - ...data.d, - token: data?.d?.token ? "[Redacted]" : undefined, - }, - }, - async () => { - const ret = await OPCodeHandler.call(this, data); - Sentry.setUser({ id: this.user_id }); - return ret; - }, - ); + return await OPCodeHandler.call(this, data); } catch (error) { - Sentry.captureException(error, { - user: { - id: this.user_id, - }, - }); console.error(`Error: Op ${data.op}`, error); // if (!this.CLOSED && this.CLOSING) return this.close(CLOSECODES.Unknown_error); diff --git a/src/util/config/Config.ts b/src/util/config/Config.ts index 56054641..1458ab4b 100644 --- a/src/util/config/Config.ts +++ b/src/util/config/Config.ts @@ -35,7 +35,6 @@ import { RegionConfiguration, RegisterConfiguration, SecurityConfiguration, - SentryConfiguration, TemplateConfiguration, UserConfiguration, } from "../config"; @@ -56,7 +55,6 @@ export class ConfigValue { kafka: KafkaConfiguration = new KafkaConfiguration(); templates: TemplateConfiguration = new TemplateConfiguration(); metrics: MetricsConfiguration = new MetricsConfiguration(); - sentry: SentryConfiguration = new SentryConfiguration(); defaults: DefaultsConfiguration = new DefaultsConfiguration(); external: ExternalTokensConfiguration = new ExternalTokensConfiguration(); email: EmailConfiguration = new EmailConfiguration(); diff --git a/src/util/config/types/SentryConfiguration.ts b/src/util/config/types/SentryConfiguration.ts deleted file mode 100644 index 3d92c62a..00000000 --- a/src/util/config/types/SentryConfiguration.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2023 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import { hostname } from "os"; - -export class SentryConfiguration { - enabled: boolean = false; - endpoint: string = - "https://05e8e3d005f34b7d97e920ae5870a5e5@sentry.thearcanebrony.net/6"; - traceSampleRate: number = 1.0; - environment: string = hostname(); -} diff --git a/src/util/config/types/index.ts b/src/util/config/types/index.ts index a141bacf..cc671bfa 100644 --- a/src/util/config/types/index.ts +++ b/src/util/config/types/index.ts @@ -34,7 +34,6 @@ export * from "./RabbitMQConfiguration"; export * from "./RegionConfiguration"; export * from "./RegisterConfiguration"; export * from "./SecurityConfiguration"; -export * from "./SentryConfiguration"; export * from "./subconfigurations"; export * from "./TemplateConfiguration"; export * from "./UsersConfiguration"; diff --git a/src/util/util/Sentry.ts b/src/util/util/Sentry.ts deleted file mode 100644 index 005b09e7..00000000 --- a/src/util/util/Sentry.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2023 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import { yellow } from "picocolors"; -import { Config } from "./Config"; - -import * as Integrations from "@sentry/node"; -import express from "express"; - -// Work around for when bundle calls api/etc -let errorHandlersUsed = false; - -export const Sentry = { - /** Call BEFORE registering your routes */ - init: async (app?: express.Application) => { - const { enabled, endpoint, traceSampleRate, environment } = - Config.get().sentry; - if (!enabled) return; - - if (Integrations.getClient()) return; // we've already initialised sentry - - console.log("[Sentry] Enabling sentry..."); - - if (traceSampleRate >= 0.8) { - console.log( - `[Sentry] ${yellow( - "Your sentry trace sampling rate is >= 80%. For large loads, this may degrade performance.", - )}`, - ); - } - - const integrations = [ - Integrations.httpIntegration(), - Integrations.rewriteFramesIntegration({ - root: __dirname, - }), - Integrations.httpIntegration(), - ...Integrations.getAutoPerformanceIntegrations(), - ]; - - //deprecated in v8? unable to test - // if (app) - // integrations.push( - // Integrations.expressIntegration({ - // app, - // }), - // ); - - Integrations.init({ - dsn: endpoint, - integrations, - tracesSampleRate: traceSampleRate, // naming? - environment, - }); - - Integrations.addEventProcessor((event) => { - 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; - }); - }, - - /** Call AFTER registering your routes */ - errorHandler: (app: express.Application) => { - if (!Config.get().sentry.enabled) return; - if (errorHandlersUsed) return; - errorHandlersUsed = true; - - Integrations.setupExpressErrorHandler(app); - - // The typings for this are broken? - // eslint-disable-next-line @typescript-eslint/no-explicit-any - app.use(function onError(err: any, req: any, res: any, next: any) { - res.statusCode = 500; - res.end(res.sentry + "\n"); - }); - }, - - close: () => { - Integrations.close(); - }, -}; diff --git a/src/util/util/index.ts b/src/util/util/index.ts index 05bdcdf8..e7d8caa9 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts @@ -37,7 +37,6 @@ export * from "./Permissions"; export * from "./RabbitMQ"; export * from "./Regex"; export * from "./Rights"; -export * from "./Sentry"; export * from "./Snowflake"; export * from "./Stopwatch"; export * from "./String";