chore(sentry): add capture exception to critical handled errors

This commit is contained in:
Nicolas Meienberger 2024-01-09 22:12:51 +01:00 committed by Nicolas Meienberger
parent fc36595468
commit 0f92cee10d
9 changed files with 27 additions and 4 deletions

View File

@ -34,9 +34,11 @@ COPY ./sentry.server.config.ts ./sentry.server.config.ts
ARG SENTRY_AUTH_TOKEN
ARG SENTRY_DISABLE_AUTO_UPLOAD
ARG TIPI_VERSION
ENV SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
ENV SENTRY_DISABLE_AUTO_UPLOAD=${SENTRY_DISABLE_AUTO_UPLOAD}
ENV TIPI_VERSION=${TIPI_VERSION}
RUN pnpm build

View File

@ -43,6 +43,7 @@
"@radix-ui/react-tabs": "^1.0.4",
"@runtipi/postgres-migrations": "^5.3.0",
"@runtipi/shared": "workspace:^",
"@sentry/integrations": "^7.92.0",
"@sentry/nextjs": "^7.92.0",
"@tabler/core": "1.0.0-beta20",
"@tabler/icons-react": "^2.44.0",

View File

@ -32,6 +32,7 @@
"@runtipi/postgres-migrations": "^5.3.0",
"@runtipi/shared": "workspace:^",
"@sentry/esbuild-plugin": "^2.10.2",
"@sentry/integrations": "^7.92.0",
"@sentry/node": "^7.92.0",
"bullmq": "^4.13.0",
"dotenv": "^16.3.1",

View File

@ -162,7 +162,6 @@ export const generateSystemEnvFile = async () => {
envMap.set('DEMO_MODE', typeof data.demoMode === 'boolean' || typeof data.demoMode === 'string' ? String(data.demoMode) : envMap.get('DEMO_MODE') || 'false');
envMap.set('GUEST_DASHBOARD', typeof data.guestDashboard === 'boolean' || typeof data.guestDashboard === 'string' ? String(data.guestDashboard) : envMap.get('GUEST_DASHBOARD') || 'false');
envMap.set('LOCAL_DOMAIN', data.localDomain || envMap.get('LOCAL_DOMAIN') || 'tipi.lan');
envMap.set('NODE_ENV', process.env.NODE_ENV || 'production');
envMap.set(
'ALLOW_ERROR_MONITORING',
typeof data.allowErrorMonitoring === 'boolean' || typeof data.allowErrorMonitoring === 'string' ? String(data.allowErrorMonitoring) : envMap.get('ALLOW_ERROR_MONITORING') || 'false',

View File

@ -37,7 +37,9 @@ export class AppExecutors {
}
private handleAppError = (err: unknown, appId: string, event: Extract<SocketEvent, { type: 'app' }>['event']) => {
Sentry.captureException(err);
Sentry.captureException(err, {
tags: { appId, event },
});
if (err instanceof Error) {
SocketManager.emit({ type: 'app', event, data: { appId, error: err.message } });

View File

@ -44,6 +44,9 @@ importers:
'@runtipi/shared':
specifier: workspace:^
version: link:packages/shared
'@sentry/integrations':
specifier: ^7.92.0
version: 7.92.0
'@sentry/nextjs':
specifier: ^7.92.0
version: 7.92.0(next@14.0.4)(react@18.2.0)
@ -440,6 +443,9 @@ importers:
'@sentry/esbuild-plugin':
specifier: ^2.10.2
version: 2.10.2
'@sentry/integrations':
specifier: ^7.92.0
version: 7.92.0
'@sentry/node':
specifier: ^7.92.0
version: 7.92.0

View File

@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs';
import { TipiConfig } from '@/server/core/TipiConfig/TipiConfig';
import { pathExists } from '@runtipi/shared';
import fs from 'fs-extra';
@ -34,6 +35,7 @@ export async function GET(request: Request) {
return new Response(file, { headers: { 'content-type': 'image/jpeg' } });
} catch (error) {
Sentry.captureException(error);
return new Response('Error', { status: 500 });
}
}

View File

@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs';
import { getUserFromCookie } from '@/server/common/session.helpers';
import { TipiConfig } from '@/server/core/TipiConfig/TipiConfig';
import fs from 'fs-extra';
@ -25,6 +26,7 @@ export async function GET() {
return new Response('Forbidden', { status: 403 });
} catch (error) {
Sentry.captureException(error);
return new Response('Error', { status: 500 });
}
}

View File

@ -2,6 +2,7 @@ import { z } from 'zod';
import { envSchema, envStringToMap, settingsSchema } from '@runtipi/shared';
import fs from 'fs-extra';
import nextConfig from 'next/config';
import * as Sentry from '@sentry/nextjs';
import { readJsonFile } from '../../common/fs.helpers';
import { Logger } from '../Logger';
@ -35,6 +36,7 @@ export class TipiConfigClass {
try {
envFile = fs.readFileSync('/runtipi/.env').toString();
} catch (e) {
Sentry.captureException(e);
Logger.error('❌ .env file not found');
}
@ -73,6 +75,7 @@ export class TipiConfigClass {
this.config = parsedConfig.data;
} else {
const errors = formatErrors(parsedConfig.error.flatten());
Sentry.captureException(new Error(`Invalid env config ${JSON.stringify(parsedConfig.error.flatten())}`));
Logger.error(`❌ Invalid env config ${JSON.stringify(errors)}`);
}
}
@ -119,8 +122,13 @@ export class TipiConfigClass {
}
public getSettings() {
const fileConfig = this.getFileConfig();
return { ...this.config, ...fileConfig };
try {
const fileConfig = this.getFileConfig();
return settingsSchema.parse({ ...this.config, ...fileConfig });
} catch (e) {
Sentry.captureException(e);
return {};
}
}
public async setConfig<T extends keyof typeof envSchema.shape>(key: T, value: z.infer<typeof envSchema>[T], writeFile = false) {