From f5bc762a3904c56a0597d081123811f1523090b0 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Sat, 7 Sep 2024 13:39:18 -0400 Subject: [PATCH 1/4] Remove sentry metric due to deprecation --- src/events/helper/DiscordCommandHandler.ts | 11 +---------- src/events/helper/TwitchCommandHandler.ts | 10 +--------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/events/helper/DiscordCommandHandler.ts b/src/events/helper/DiscordCommandHandler.ts index fb78289..761e594 100644 --- a/src/events/helper/DiscordCommandHandler.ts +++ b/src/events/helper/DiscordCommandHandler.ts @@ -7,7 +7,7 @@ import { softBanCommand, unbanCommand, FeedbackCommand } from "../../commands/discord"; import { baseCommand } from "../../core/baseCommand"; -import { captureException, metrics } from "@sentry/node"; +import { captureException } from "@sentry/node"; import { DiscordClient } from "../../core/DiscordClient"; import { createHash, timingSafeEqual } from "crypto"; @@ -103,15 +103,6 @@ export class DiscordCommandHandler { } } - - // Execute command, assuming all the checks are passed (and track their usages) - if(interaction.user.id !== "233955058604179457") - metrics.increment("discord.command.executed", 1, { - tags: { - command: interaction.commandName, - type: interaction instanceof CommandInteraction ? "slash" : "context" - } - }); // Attach identifier to save the error ID on redis try { await command.execute(interaction); } diff --git a/src/events/helper/TwitchCommandHandler.ts b/src/events/helper/TwitchCommandHandler.ts index 60ea6c1..a50159c 100644 --- a/src/events/helper/TwitchCommandHandler.ts +++ b/src/events/helper/TwitchCommandHandler.ts @@ -1,7 +1,7 @@ import { ChatUserstate } from "tmi.js"; import { TwitchClient } from "../../core/TwitchClient"; import { baseTCommand } from "../../core/baseCommand"; -import { captureException, metrics } from "@sentry/node"; +import { captureException } from "@sentry/node"; import { DiscordCommand, LinkCommand, LurkCommand } from "../../commands/twitch"; import { TwitchUser } from "../../utils/TwitchUser"; @@ -36,14 +36,6 @@ export async function processCommand(eventData: eventType): Promise Date: Sat, 7 Sep 2024 13:46:04 -0400 Subject: [PATCH 2/4] IORedis Instrumentation --- package-lock.json | 60 ++++++++++++++++++----------------------------- package.json | 1 + src/loader.ts | 6 ++++- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index edc437a..8d08442 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@discordjs/rest": "^2.0.0", "@opentelemetry/exporter-trace-otlp-http": "^0.53.0", "@opentelemetry/instrumentation": "^0.53.0", + "@opentelemetry/instrumentation-ioredis": "^0.43.0", "@opentelemetry/resources": "^1.24.1", "@opentelemetry/sdk-trace-base": "^1.24.1", "@opentelemetry/sdk-trace-node": "^1.24.1", @@ -2897,46 +2898,14 @@ } }, "node_modules/@opentelemetry/instrumentation-ioredis": { - "version": "0.42.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-ioredis/-/instrumentation-ioredis-0.42.0.tgz", - "integrity": "sha512-P11H168EKvBB9TUSasNDOGJCSkpT44XgoM6d3gRIWAa9ghLpYhl0uRkS8//MqPzcJVHr3h3RmfXIpiYLjyIZTw==", + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-ioredis/-/instrumentation-ioredis-0.43.0.tgz", + "integrity": "sha512-i3Dke/LdhZbiUAEImmRG3i7Dimm/BD7t8pDDzwepSvIQ6s2X6FPia7561gw+64w+nx0+G9X14D7rEfaMEmmjig==", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/instrumentation": "^0.52.0", + "@opentelemetry/instrumentation": "^0.53.0", "@opentelemetry/redis-common": "^0.36.2", - "@opentelemetry/semantic-conventions": "^1.23.0" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": "^1.3.0" - } - }, - "node_modules/@opentelemetry/instrumentation-ioredis/node_modules/@opentelemetry/api-logs": { - "version": "0.52.1", - "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.52.1.tgz", - "integrity": "sha512-qnSqB2DQ9TPP96dl8cDubDvrUyWc0/sK81xHTK8eSUspzDM3bsewX903qclQFvVhgStjRWdC5bLb3kQqMkfV5A==", - "license": "Apache-2.0", - "dependencies": { - "@opentelemetry/api": "^1.0.0" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/@opentelemetry/instrumentation-ioredis/node_modules/@opentelemetry/instrumentation": { - "version": "0.52.1", - "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.52.1.tgz", - "integrity": "sha512-uXJbYU/5/MBHjMp1FqrILLRuiJCs3Ofk0MeRDk8g1S1gD47U8X3JnSwcMO1rtRo1x1a7zKaQHaoYu49p/4eSKw==", - "license": "Apache-2.0", - "dependencies": { - "@opentelemetry/api-logs": "0.52.1", - "@types/shimmer": "^1.0.2", - "import-in-the-middle": "^1.8.1", - "require-in-the-middle": "^7.1.1", - "semver": "^7.5.2", - "shimmer": "^1.2.1" + "@opentelemetry/semantic-conventions": "^1.27.0" }, "engines": { "node": ">=14" @@ -4118,6 +4087,23 @@ "@opentelemetry/api": "^1.3.0" } }, + "node_modules/@sentry/node/node_modules/@opentelemetry/instrumentation-ioredis": { + "version": "0.42.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-ioredis/-/instrumentation-ioredis-0.42.0.tgz", + "integrity": "sha512-P11H168EKvBB9TUSasNDOGJCSkpT44XgoM6d3gRIWAa9ghLpYhl0uRkS8//MqPzcJVHr3h3RmfXIpiYLjyIZTw==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/instrumentation": "^0.52.0", + "@opentelemetry/redis-common": "^0.36.2", + "@opentelemetry/semantic-conventions": "^1.23.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.3.0" + } + }, "node_modules/@sentry/node/node_modules/@sentry/opentelemetry": { "version": "8.28.0", "resolved": "https://registry.npmjs.org/@sentry/opentelemetry/-/opentelemetry-8.28.0.tgz", diff --git a/package.json b/package.json index 8899de3..254fad9 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "@discordjs/rest": "^2.0.0", "@opentelemetry/exporter-trace-otlp-http": "^0.53.0", "@opentelemetry/instrumentation": "^0.53.0", + "@opentelemetry/instrumentation-ioredis": "^0.43.0", "@opentelemetry/resources": "^1.24.1", "@opentelemetry/sdk-trace-base": "^1.24.1", "@opentelemetry/sdk-trace-node": "^1.24.1", diff --git a/src/loader.ts b/src/loader.ts index 8199552..8a7c230 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -92,6 +92,7 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { PrismaInstrumentation } from '@prisma/instrumentation'; +import { IORedisInstrumentation } from "@opentelemetry/instrumentation-ioredis"; import { Resource } from '@opentelemetry/resources'; const provider = new NodeTracerProvider({ @@ -103,7 +104,10 @@ provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); registerInstrumentations({ tracerProvider: provider, - instrumentations: [new PrismaInstrumentation()], + instrumentations: [ + new PrismaInstrumentation(), + new IORedisInstrumentation(), + ], }); provider.register(); From 2e9dc6103cb09a69c6c9dece8089585c4da9062e Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Sat, 7 Sep 2024 13:58:30 -0400 Subject: [PATCH 3/4] Ignore transaction from YT callback --- src/loader.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/loader.ts b/src/loader.ts index 8a7c230..086bb39 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -19,7 +19,7 @@ if(process.env["COMMITHASH"] === undefined) { // Run Sentry first as required by the docs -import { expressIntegration, extraErrorDataIntegration, prismaIntegration, rewriteFramesIntegration, init as sentryInit } from "@sentry/node"; +import { expressIntegration, extraErrorDataIntegration, prismaIntegration, redisIntegration, rewriteFramesIntegration, init as sentryInit } from "@sentry/node"; import { DiscordAPIError } from "discord.js"; import { relative } from "path"; import { APIErrors } from "./utils/discordErrorCode"; @@ -44,6 +44,7 @@ sentryInit({ } }), prismaIntegration(), + redisIntegration(), expressIntegration(), ], @@ -80,6 +81,13 @@ sentryInit({ return evnt; }, + beforeSendTransaction: (transaction) => { + // Ignore callback stuff from PubSubHubbub + if(transaction.transaction == "POST /UwU/youtube/callback/") + return null; + return transaction; + }, + release: process.env['COMMITHASH'], environment: process.env["ENVIRONMENT"] }); From a95c5658318f4ffe4382a3b6cab450a5ceee1bb9 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Sat, 7 Sep 2024 14:01:57 -0400 Subject: [PATCH 4/4] Ignore all methods from that path --- src/loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loader.ts b/src/loader.ts index 086bb39..9bd58c4 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -83,7 +83,7 @@ sentryInit({ beforeSendTransaction: (transaction) => { // Ignore callback stuff from PubSubHubbub - if(transaction.transaction == "POST /UwU/youtube/callback/") + if(new RegExp("/UwU/youtube/callback/").test(transaction.transaction ?? "")) return null; return transaction; },