chore: overhaul infrastructure and integrate @mintel packages
Some checks failed
🧪 CI (QA) / 🧪 Quality Assurance (push) Failing after 1m3s
Some checks failed
🧪 CI (QA) / 🧪 Quality Assurance (push) Failing after 1m3s
- Restructure to pnpm monorepo (site moved to apps/web) - Integrate @mintel/tsconfig, @mintel/eslint-config, @mintel/husky-config - Implement Docker service architecture (Varnish, Directus, Gatekeeper) - Setup environment-aware Gitea Actions deployment
This commit is contained in:
76
apps/web/src/utils/error-tracking/glitchtip-adapter.ts
Normal file
76
apps/web/src/utils/error-tracking/glitchtip-adapter.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* GlitchTip Error Tracking Adapter
|
||||
* GlitchTip is Sentry-compatible.
|
||||
*/
|
||||
|
||||
import type { ErrorTrackingAdapter, ErrorContext, ErrorTrackingConfig } from './interfaces';
|
||||
|
||||
export class GlitchTipAdapter implements ErrorTrackingAdapter {
|
||||
private dsn: string;
|
||||
|
||||
constructor(config: ErrorTrackingConfig) {
|
||||
this.dsn = config.dsn;
|
||||
this.init(config);
|
||||
}
|
||||
|
||||
private init(config: ErrorTrackingConfig) {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
// In a real scenario, we would import @sentry/nextjs or @sentry/browser
|
||||
// For this implementation, we assume Sentry is available globally or
|
||||
// we provide the structure that would call the SDK.
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.init({
|
||||
dsn: this.dsn,
|
||||
environment: config.environment || 'production',
|
||||
release: config.release,
|
||||
debug: config.debug || false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
captureException(error: any, context?: ErrorContext): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.captureException(error, context);
|
||||
} else {
|
||||
console.error('[GlitchTip] Exception captured (Sentry not loaded):', error, context);
|
||||
}
|
||||
}
|
||||
|
||||
captureMessage(message: string, context?: ErrorContext): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.captureMessage(message, context);
|
||||
} else {
|
||||
console.log('[GlitchTip] Message captured (Sentry not loaded):', message, context);
|
||||
}
|
||||
}
|
||||
|
||||
setUser(user: ErrorContext['user']): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.setUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
setTag(key: string, value: string): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.setTag(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
setExtra(key: string, value: any): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const w = window as any;
|
||||
if (w.Sentry) {
|
||||
w.Sentry.setExtra(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
apps/web/src/utils/error-tracking/index.ts
Normal file
61
apps/web/src/utils/error-tracking/index.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Error Tracking Service - Main entry point with DI
|
||||
*/
|
||||
|
||||
import type { ErrorTrackingAdapter, ErrorContext, ErrorTrackingConfig } from './interfaces';
|
||||
import { GlitchTipAdapter } from './glitchtip-adapter';
|
||||
|
||||
export class ErrorTrackingService {
|
||||
private adapter: ErrorTrackingAdapter;
|
||||
|
||||
constructor(adapter: ErrorTrackingAdapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
captureException(error: any, context?: ErrorContext): void {
|
||||
this.adapter.captureException(error, context);
|
||||
}
|
||||
|
||||
captureMessage(message: string, context?: ErrorContext): void {
|
||||
this.adapter.captureMessage(message, context);
|
||||
}
|
||||
|
||||
setUser(user: ErrorContext['user']): void {
|
||||
this.adapter.setUser(user);
|
||||
}
|
||||
|
||||
setTag(key: string, value: string): void {
|
||||
this.adapter.setTag(key, value);
|
||||
}
|
||||
|
||||
setExtra(key: string, value: any): void {
|
||||
this.adapter.setExtra(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function
|
||||
export function createGlitchTipErrorTracking(config: ErrorTrackingConfig): ErrorTrackingService {
|
||||
return new ErrorTrackingService(new GlitchTipAdapter(config));
|
||||
}
|
||||
|
||||
// Default singleton
|
||||
let defaultErrorTracking: ErrorTrackingService | null = null;
|
||||
|
||||
export function getDefaultErrorTracking(): ErrorTrackingService {
|
||||
if (!defaultErrorTracking) {
|
||||
defaultErrorTracking = createGlitchTipErrorTracking({
|
||||
dsn: process.env.NEXT_PUBLIC_GLITCHTIP_DSN || '',
|
||||
environment: process.env.NODE_ENV,
|
||||
});
|
||||
}
|
||||
return defaultErrorTracking;
|
||||
}
|
||||
|
||||
// Convenience functions
|
||||
export function captureException(error: any, context?: ErrorContext): void {
|
||||
getDefaultErrorTracking().captureException(error, context);
|
||||
}
|
||||
|
||||
export function captureMessage(message: string, context?: ErrorContext): void {
|
||||
getDefaultErrorTracking().captureMessage(message, context);
|
||||
}
|
||||
29
apps/web/src/utils/error-tracking/interfaces.ts
Normal file
29
apps/web/src/utils/error-tracking/interfaces.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Error Tracking interfaces - decoupled contracts
|
||||
*/
|
||||
|
||||
export interface ErrorContext {
|
||||
extra?: Record<string, any>;
|
||||
tags?: Record<string, string>;
|
||||
user?: {
|
||||
id?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
};
|
||||
level?: 'fatal' | 'error' | 'warning' | 'info' | 'debug';
|
||||
}
|
||||
|
||||
export interface ErrorTrackingAdapter {
|
||||
captureException(error: any, context?: ErrorContext): void;
|
||||
captureMessage(message: string, context?: ErrorContext): void;
|
||||
setUser(user: ErrorContext['user']): void;
|
||||
setTag(key: string, value: string): void;
|
||||
setExtra(key: string, value: any): void;
|
||||
}
|
||||
|
||||
export interface ErrorTrackingConfig {
|
||||
dsn: string;
|
||||
environment?: string;
|
||||
release?: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user