-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from gowon-bot/error-reporting
Error reporting
- Loading branch information
Showing
8 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,7 @@ config.json | |
ormconfig.json | ||
|
||
docker-compose.*.yml | ||
Dockerfile.dev | ||
Dockerfile.dev | ||
|
||
# Sentry Auth Token | ||
.sentryclirc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as Sentry from "@sentry/node"; | ||
import config from "../../../config.json"; | ||
import { ClientError } from "../../errors/errors"; | ||
import { GowonContext } from "../../lib/context/Context"; | ||
import { BaseService } from "../BaseService"; | ||
|
||
export class ReportingService extends BaseService { | ||
async init() { | ||
Sentry.init({ | ||
dsn: config.sentryDSN, | ||
}); | ||
} | ||
|
||
public reportError(ctx: GowonContext, e: Error): void { | ||
Sentry.withScope((scope) => { | ||
this.addContextToScope(ctx, scope); | ||
|
||
if (e instanceof ClientError) { | ||
scope.setLevel("log"); | ||
} | ||
|
||
Sentry.captureException(e); | ||
}); | ||
} | ||
|
||
private addContextToScope(ctx: GowonContext, scope: Sentry.Scope) { | ||
scope.setTag("command-name", ctx.command?.friendlyNameWithParent); | ||
|
||
scope.setUser({ | ||
id: ctx.author.id, | ||
username: ctx.author.username, | ||
}); | ||
|
||
scope.setExtra("user", { | ||
discord: { id: ctx.author.id, username: ctx.author.username }, | ||
}); | ||
scope.setExtra("arguments", ctx.command.parsedArguments ?? {}); | ||
scope.setExtra("guild-id", ctx.guild?.id ?? "DM"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters