mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 00:48:18 +01:00
feat: ✨ Add Sentry support
This commit is contained in:
parent
0679971cc0
commit
5061735da7
|
|
@ -51,6 +51,7 @@
|
||||||
- [x] Advanced Roles and Permissions API.
|
- [x] Advanced Roles and Permissions API.
|
||||||
- [x] HTTP proxy support
|
- [x] HTTP proxy support
|
||||||
- [x] Tor hidden service support
|
- [x] Tor hidden service support
|
||||||
|
- [x] Sentry logging support
|
||||||
- [x] Ability to change the domain name in a single config change, without any database edits
|
- [x] Ability to change the domain name in a single config change, without any database edits
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
|
||||||
2
app.ts
2
app.ts
|
|
@ -1,4 +1,5 @@
|
||||||
import { errorResponse, jsonResponse, response } from "@/response";
|
import { errorResponse, jsonResponse, response } from "@/response";
|
||||||
|
import { sentry } from "@/sentry";
|
||||||
import { Hono } from "@hono/hono";
|
import { Hono } from "@hono/hono";
|
||||||
import { getLogger } from "@logtape/logtape";
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
|
|
@ -96,6 +97,7 @@ export const appFactory = async () => {
|
||||||
app.onError((error) => {
|
app.onError((error) => {
|
||||||
const serverLogger = getLogger("server");
|
const serverLogger = getLogger("server");
|
||||||
serverLogger.error`${error}`;
|
serverLogger.error`${error}`;
|
||||||
|
sentry?.captureException(error);
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
{
|
{
|
||||||
error: "A server error occured",
|
error: "A server error occured",
|
||||||
|
|
|
||||||
|
|
@ -389,6 +389,18 @@ log_ip = false
|
||||||
# Log all filtered objects
|
# Log all filtered objects
|
||||||
log_filters = true
|
log_filters = true
|
||||||
|
|
||||||
|
[logging.sentry]
|
||||||
|
# Whether to enable https://sentry.io error logging
|
||||||
|
enabled = false
|
||||||
|
# Sentry DSN for error logging
|
||||||
|
dsn = ""
|
||||||
|
debug = false
|
||||||
|
|
||||||
|
sample_rate = 1.0
|
||||||
|
traces_sample_rate = 1.0
|
||||||
|
max_breadcrumbs = 100
|
||||||
|
# environment = "production"
|
||||||
|
|
||||||
[logging.storage]
|
[logging.storage]
|
||||||
# Path to logfile for requests
|
# Path to logfile for requests
|
||||||
requests = "logs/requests.log"
|
requests = "logs/requests.log"
|
||||||
|
|
|
||||||
2
index.ts
2
index.ts
|
|
@ -1,4 +1,5 @@
|
||||||
import { configureLoggers } from "@/loggers";
|
import { configureLoggers } from "@/loggers";
|
||||||
|
import { sentry } from "@/sentry";
|
||||||
import { createServer } from "@/server";
|
import { createServer } from "@/server";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
import { appFactory } from "~/app";
|
import { appFactory } from "~/app";
|
||||||
|
|
@ -6,6 +7,7 @@ import { setupDatabase } from "./drizzle/db";
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
await import("./setup");
|
await import("./setup");
|
||||||
|
sentry?.captureMessage("Server started");
|
||||||
}
|
}
|
||||||
|
|
||||||
await setupDatabase();
|
await setupDatabase();
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@
|
||||||
"@lysand-org/client": "^0.2.5",
|
"@lysand-org/client": "^0.2.5",
|
||||||
"@lysand-org/federation": "2.1.8",
|
"@lysand-org/federation": "2.1.8",
|
||||||
"@oclif/core": "^4.0.14",
|
"@oclif/core": "^4.0.14",
|
||||||
|
"@sentry/bun": "^8.19.0",
|
||||||
"@tufjs/canonical-json": "^2.0.0",
|
"@tufjs/canonical-json": "^2.0.0",
|
||||||
"altcha-lib": "^0.4.1",
|
"altcha-lib": "^0.4.1",
|
||||||
"blurhash": "^2.0.5",
|
"blurhash": "^2.0.5",
|
||||||
|
|
|
||||||
|
|
@ -568,6 +568,20 @@ export const configValidator = z.object({
|
||||||
.default("info"),
|
.default("info"),
|
||||||
log_ip: z.boolean().default(false),
|
log_ip: z.boolean().default(false),
|
||||||
log_filters: z.boolean().default(true),
|
log_filters: z.boolean().default(true),
|
||||||
|
sentry: z
|
||||||
|
.object({
|
||||||
|
enabled: z.boolean().default(false),
|
||||||
|
dsn: z.string().url().or(z.literal("")).optional(),
|
||||||
|
debug: z.boolean().default(false),
|
||||||
|
sample_rate: z.number().min(0).max(1.0).default(1.0),
|
||||||
|
traces_sample_rate: z.number().min(0).max(1.0).default(1.0),
|
||||||
|
max_breadcrumbs: z.number().default(100),
|
||||||
|
environment: z.string().optional(),
|
||||||
|
})
|
||||||
|
.refine(
|
||||||
|
(arg) => (arg.enabled ? !!arg.dsn : true),
|
||||||
|
"When sentry is enabled, DSN must be set",
|
||||||
|
),
|
||||||
storage: z
|
storage: z
|
||||||
.object({
|
.object({
|
||||||
requests: z.string().default("logs/requests.log"),
|
requests: z.string().default("logs/requests.log"),
|
||||||
|
|
@ -582,6 +596,13 @@ export const configValidator = z.object({
|
||||||
log_level: "info",
|
log_level: "info",
|
||||||
log_ip: false,
|
log_ip: false,
|
||||||
log_filters: true,
|
log_filters: true,
|
||||||
|
sentry: {
|
||||||
|
enabled: false,
|
||||||
|
debug: false,
|
||||||
|
sample_rate: 1.0,
|
||||||
|
traces_sample_rate: 1.0,
|
||||||
|
max_breadcrumbs: 100,
|
||||||
|
},
|
||||||
storage: {
|
storage: {
|
||||||
requests: "logs/requests.log",
|
requests: "logs/requests.log",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
18
utils/sentry.ts
Normal file
18
utils/sentry.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import * as Sentry from "@sentry/bun";
|
||||||
|
import { config } from "config-manager";
|
||||||
|
import pkg from "~/package.json";
|
||||||
|
|
||||||
|
const sentryInstance =
|
||||||
|
config.logging.sentry.enabled &&
|
||||||
|
Sentry.init({
|
||||||
|
dsn: config.logging.sentry.dsn,
|
||||||
|
debug: config.logging.sentry.debug,
|
||||||
|
sampleRate: config.logging.sentry.sample_rate,
|
||||||
|
maxBreadcrumbs: config.logging.sentry.max_breadcrumbs,
|
||||||
|
tracesSampleRate: config.logging.sentry.traces_sample_rate,
|
||||||
|
environment: config.logging.sentry.environment,
|
||||||
|
tracePropagationTargets: [config.http.bind],
|
||||||
|
release: pkg.version,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const sentry = sentryInstance || undefined;
|
||||||
Loading…
Reference in a new issue