-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: integrate sentry monitoring (#43)
* integrate sentry api observability * update error handling * parse error message from thirdweb engine * add fetch depth to release step * add build steps to release * add sentry vars to terraform * fix sentry_environment vals * fix sentry var nesting * fix dev env folder in readme
- Loading branch information
1 parent
786c1c7
commit 003350e
Showing
24 changed files
with
1,300 additions
and
438 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
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,10 @@ | ||
import * as Sentry from "@sentry/node"; | ||
import { nodeProfilingIntegration } from "@sentry/profiling-node"; | ||
|
||
Sentry.init({ | ||
dsn: process.env.SENTRY_DSN, | ||
environment: process.env.SENTRY_ENVIRONMENT || "production", | ||
integrations: [nodeProfilingIntegration(), Sentry.prismaIntegration()], | ||
tracesSampleRate: 1.0, | ||
profilesSampleRate: 1.0, | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import type { FastifyInstance } from "fastify"; | ||
|
||
export const withErrorHandler = async (app: FastifyInstance) => | ||
app.setErrorHandler((err, req, reply) => { | ||
console.error(`Error occurred in ${req.routerPath}:`, err); | ||
reply.code(err.statusCode ?? 500).send({ error: err.message }); | ||
app.setErrorHandler((err, _, reply) => { | ||
reply.code(err.statusCode ?? 500).send({ ...err, error: err.message }); | ||
}); |
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
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,52 @@ | ||
import * as Sentry from "@sentry/node"; | ||
import { ApiError } from "@thirdweb-dev/engine"; | ||
|
||
type ErrorCode = | ||
| "TDK_UNAUTHORIZED" | ||
| "TDK_FORBIDDEN" | ||
| "TDK_NOT_FOUND" | ||
| "TDK_CREATE_TRANSACTION" | ||
| "TDK_READ_TRANSACTION"; | ||
|
||
const ERROR_STATUS_CODE_MAPPING: Partial<Record<ErrorCode, number>> = { | ||
TDK_UNAUTHORIZED: 401, | ||
TDK_FORBIDDEN: 403, | ||
TDK_NOT_FOUND: 404, | ||
}; | ||
|
||
export class TdkError extends Error { | ||
code: ErrorCode; | ||
statusCode: number; | ||
data: object | undefined; | ||
|
||
constructor({ | ||
code, | ||
message, | ||
statusCode, | ||
data, | ||
}: { | ||
code: ErrorCode; | ||
message: string; | ||
statusCode?: number; | ||
data?: object; | ||
}) { | ||
super(message); | ||
this.name = "TdkError"; | ||
this.code = code; | ||
this.statusCode = statusCode ?? ERROR_STATUS_CODE_MAPPING[code] ?? 500; | ||
this.data = data; | ||
Sentry.setExtra("error", this); | ||
} | ||
} | ||
|
||
export const parseEngineErrorMessage = (err: ApiError | Error) => { | ||
if (err instanceof ApiError && err.body.error?.message) { | ||
return err.body.error.message as string; | ||
} | ||
|
||
if (err instanceof Error) { | ||
return err.message; | ||
} | ||
|
||
return undefined; | ||
}; |
Oops, something went wrong.