Skip to content

Commit

Permalink
Merge pull request #140 from zhiyan114/master
Browse files Browse the repository at this point in the history
New Sentry Config
  • Loading branch information
zhiyan114 authored Sep 8, 2024
2 parents 05e0296 + 3766194 commit 51eade3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 58 deletions.
60 changes: 23 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 1 addition & 10 deletions src/events/helper/DiscordCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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); }
Expand Down
10 changes: 1 addition & 9 deletions src/events/helper/TwitchCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -36,14 +36,6 @@ export async function processCommand(eventData: eventType): Promise<boolean | un
return false;
}

// Execute command, assuming all the checks are passed (and track their usages)
if(eventData.user.id !== "128185688")
metrics.increment("twitch.command.executed", 1, {
tags: {
command: cmdName
}
});

try {
await command.execute({
channel: eventData.channel,
Expand Down
16 changes: 14 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -44,6 +44,7 @@ sentryInit({
}
}),
prismaIntegration(),
redisIntegration(),
expressIntegration(),
],

Expand Down Expand Up @@ -80,6 +81,13 @@ sentryInit({
return evnt;
},

beforeSendTransaction: (transaction) => {
// Ignore callback stuff from PubSubHubbub
if(new RegExp("/UwU/youtube/callback/").test(transaction.transaction ?? ""))
return null;
return transaction;
},

release: process.env['COMMITHASH'],
environment: process.env["ENVIRONMENT"]
});
Expand All @@ -92,6 +100,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({
Expand All @@ -103,7 +112,10 @@ provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

registerInstrumentations({
tracerProvider: provider,
instrumentations: [new PrismaInstrumentation()],
instrumentations: [
new PrismaInstrumentation(),
new IORedisInstrumentation(),
],
});
provider.register();

Expand Down

0 comments on commit 51eade3

Please sign in to comment.