Update sentry to latest

This commit is contained in:
Emma [it/its]@Rory& 2024-10-29 21:44:26 +01:00
parent 21f88e400d
commit e0d0022675
4 changed files with 866 additions and 129 deletions

945
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -68,8 +68,7 @@
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.682.0", "@aws-sdk/client-s3": "^3.682.0",
"@sentry/integrations": "^7.66.0", "@sentry/node": "^8.35.0",
"@sentry/node": "^7.119.2",
"ajv": "^8.17.1", "ajv": "^8.17.1",
"ajv-formats": "2.1.1", "ajv-formats": "2.1.1",
"amqplib": "^0.10.4", "amqplib": "^0.10.4",

View File

@ -89,11 +89,11 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
} }
try { try {
return await Sentry.startActiveSpan( return await Sentry.startSpan( // Emma [it/its]@Rory&: is this the right function to migrate to in v8?
{ {
op: "websocket.server", op: "websocket.server",
name: `GATEWAY ${OPCODES[data.op]}`, name: `GATEWAY ${OPCODES[data.op]}`,
data: { attributes: { // this needs to be reworked :)
...data.d, ...data.d,
token: data?.d?.token ? "[Redacted]" : undefined, token: data?.d?.token ? "[Redacted]" : undefined,
}, },

View File

@ -19,8 +19,7 @@
import { yellow } from "picocolors"; import { yellow } from "picocolors";
import { Config } from "./Config"; import { Config } from "./Config";
import * as Integrations from "@sentry/integrations"; import * as Integrations from "@sentry/node";
import * as SentryNode from "@sentry/node";
import express from "express"; import express from "express";
// Work around for when bundle calls api/etc // Work around for when bundle calls api/etc
@ -33,7 +32,7 @@ export const Sentry = {
Config.get().sentry; Config.get().sentry;
if (!enabled) return; if (!enabled) return;
if (SentryNode.getCurrentHub().getClient()) return; // we've already initialised sentry if (Integrations.getClient()) return; // we've already initialised sentry
console.log("[Sentry] Enabling sentry..."); console.log("[Sentry] Enabling sentry...");
@ -46,32 +45,30 @@ export const Sentry = {
} }
const integrations = [ const integrations = [
new SentryNode.Integrations.Http({ tracing: true }), Integrations.httpIntegration(),
new Integrations.RewriteFrames({ Integrations.rewriteFramesIntegration({
root: __dirname, root: __dirname,
}), }),
new SentryNode.Integrations.Http({ Integrations.httpIntegration(),
tracing: true, ...Integrations.getAutoPerformanceIntegrations(),
breadcrumbs: true,
}),
...SentryNode.autoDiscoverNodePerformanceMonitoringIntegrations(),
]; ];
if (app) //deprecated in v8? unable to test
integrations.push( // if (app)
new SentryNode.Integrations.Express({ // integrations.push(
app, // Integrations.expressIntegration({
}), // app,
); // }),
// );
SentryNode.init({ Integrations.init({
dsn: endpoint, dsn: endpoint,
integrations, integrations,
tracesSampleRate: traceSampleRate, // naming? tracesSampleRate: traceSampleRate, // naming?
environment, environment,
}); });
SentryNode.addGlobalEventProcessor((event) => { Integrations.addEventProcessor((event) => {
if (event.transaction) { if (event.transaction) {
// Rewrite things that look like IDs to `:id` for sentry // Rewrite things that look like IDs to `:id` for sentry
event.transaction = event.transaction event.transaction = event.transaction
@ -109,11 +106,6 @@ export const Sentry = {
return event; return event;
}); });
if (app) {
app.use(SentryNode.Handlers.requestHandler());
app.use(SentryNode.Handlers.tracingHandler());
}
}, },
/** Call AFTER registering your routes */ /** Call AFTER registering your routes */
@ -122,7 +114,8 @@ export const Sentry = {
if (errorHandlersUsed) return; if (errorHandlersUsed) return;
errorHandlersUsed = true; errorHandlersUsed = true;
app.use(SentryNode.Handlers.errorHandler()); Integrations.setupExpressErrorHandler(app);
// The typings for this are broken? // The typings for this are broken?
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
app.use(function onError(err: any, req: any, res: any, next: any) { app.use(function onError(err: any, req: any, res: any, next: any) {
@ -132,6 +125,6 @@ export const Sentry = {
}, },
close: () => { close: () => {
SentryNode.close(); Integrations.close();
}, },
}; };