The app is now wired to GlitchTip with the Sentry SDKs
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
|
||||
import type { ApiError } from '@/types/api';
|
||||
import { notifyAccessTokenRefreshed } from '@/lib/auth/accessTokenEvents';
|
||||
import { reportUnexpectedApiFailure } from '@/lib/error-tracking/reportUnexpectedApiFailure';
|
||||
|
||||
interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
||||
_retry?: boolean;
|
||||
@@ -46,6 +47,7 @@ function shouldSkipRefreshRetry(url: string | undefined): boolean {
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
reportUnexpectedApiFailure(error);
|
||||
const originalRequest = error.config as CustomAxiosRequestConfig;
|
||||
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import type { AxiosError } from 'axios';
|
||||
|
||||
/** Report network failures and HTTP 5xx only — not coded 4xx AppExceptions. */
|
||||
export function reportUnexpectedApiFailure(error: AxiosError): void {
|
||||
const status = error.response?.status;
|
||||
if (status !== undefined && status < 500) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sentry.captureException(error, {
|
||||
tags: {
|
||||
api_status: status ? String(status) : 'network',
|
||||
},
|
||||
extra: {
|
||||
url: error.config?.url,
|
||||
method: error.config?.method,
|
||||
},
|
||||
});
|
||||
}
|
||||
15
frontend/src/lib/error-tracking/sentry.server.config.ts
Normal file
15
frontend/src/lib/error-tracking/sentry.server.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import { sentrySharedOptions } from '@/lib/error-tracking/sentrySharedOptions';
|
||||
|
||||
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN?.trim();
|
||||
|
||||
if (dsn) {
|
||||
Sentry.init({
|
||||
dsn,
|
||||
environment:
|
||||
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT?.trim() ||
|
||||
process.env.NODE_ENV ||
|
||||
'development',
|
||||
...sentrySharedOptions(),
|
||||
});
|
||||
}
|
||||
28
frontend/src/lib/error-tracking/sentrySharedOptions.ts
Normal file
28
frontend/src/lib/error-tracking/sentrySharedOptions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { ErrorEvent } from '@sentry/core';
|
||||
|
||||
/** Shared Sentry/GlitchTip options — no session replay, no PII in payloads. */
|
||||
export function sentrySharedOptions() {
|
||||
return {
|
||||
sendDefaultPii: false as const,
|
||||
tracesSampleRate: 0,
|
||||
replaysSessionSampleRate: 0,
|
||||
replaysOnErrorSampleRate: 0,
|
||||
beforeSend(event: ErrorEvent): ErrorEvent {
|
||||
if (event.request) {
|
||||
delete event.request.cookies;
|
||||
delete event.request.data;
|
||||
if (event.request.headers) {
|
||||
delete event.request.headers.cookie;
|
||||
delete event.request.headers.authorization;
|
||||
delete event.request.headers.Authorization;
|
||||
}
|
||||
}
|
||||
if (event.user) {
|
||||
delete event.user.email;
|
||||
delete event.user.ip_address;
|
||||
delete event.user.username;
|
||||
}
|
||||
return event;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user