feat: Integrate Cronitor RUM

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 15:07:31 +00:00
parent e1ffba593a
commit 0106bdb1d5
7 changed files with 160 additions and 16 deletions

View File

@@ -58,15 +58,42 @@ export const breadcrumb = {
level: 'info',
data,
});
// Track critical user actions in Cronitor
const criticalActions = ['submit', 'delete', 'update', 'create', 'login', 'logout'];
const isCritical = criticalActions.some(ca => action.toLowerCase().includes(ca));
if (isCritical && typeof window !== 'undefined' && window.cronitor) {
window.cronitor.track('critical_user_action', {
action,
component,
timestamp: new Date().toISOString(),
});
}
},
apiCall: (endpoint: string, method: string, status?: number) => {
const isError = status && status >= 400;
breadcrumbManager.add({
category: 'api_call',
message: `API ${method} ${endpoint}`,
level: status && status >= 400 ? 'error' : 'info',
level: isError ? 'error' : 'info',
data: { endpoint, method, status },
});
// Track significant API calls in Cronitor
if (typeof window !== 'undefined' && window.cronitor) {
// Only track errors and slow requests
if (isError || (status && status >= 500)) {
window.cronitor.track('api_error', {
endpoint,
method,
status,
severity: status >= 500 ? 'high' : 'medium',
});
}
}
},
stateChange: (description: string, data?: Record<string, any>) => {

View File

@@ -4,6 +4,16 @@ import { supabase } from '@/integrations/supabase/client';
import { breadcrumbManager } from './errorBreadcrumbs';
import { captureEnvironmentContext } from './environmentContext';
// Cronitor RUM integration
declare global {
interface Window {
cronitor?: {
track: (eventName: string, data?: Record<string, any>) => void;
error: (error: Error | string, metadata?: Record<string, any>) => void;
};
}
}
export type ErrorContext = {
action: string;
userId?: string;
@@ -123,6 +133,25 @@ export const handleError = (
});
}
// Track error in Cronitor RUM
if (typeof window !== 'undefined' && window.cronitor) {
try {
window.cronitor.error(
error instanceof Error ? error : new Error(errorMessage),
{
errorId,
errorName,
action: context.action,
userId: context.userId,
supabaseError: supabaseErrorDetails,
breadcrumbCount: breadcrumbManager.getAll().length,
}
);
} catch (cronitorError) {
logger.error('Failed to track error in Cronitor', { cronitorError });
}
}
// Log to database with breadcrumbs (non-blocking)
try {
const envContext = captureEnvironmentContext();
@@ -218,6 +247,21 @@ export const handleNonCriticalError = (
severity: 'low',
});
// Track non-critical error in Cronitor (lower severity)
if (typeof window !== 'undefined' && window.cronitor) {
try {
window.cronitor.track('non_critical_error', {
errorId,
errorMessage,
action: context.action,
userId: context.userId,
severity: 'low',
});
} catch (cronitorError) {
logger.error('Failed to track non-critical error in Cronitor', { cronitorError });
}
}
// Log to database with breadcrumbs (non-blocking, fire-and-forget)
try {
const envContext = captureEnvironmentContext();

View File

@@ -243,9 +243,28 @@ export async function withRetry<T>(
error: error instanceof Error ? error.message : String(error)
});
// Track exhausted retries in Cronitor
if (typeof window !== 'undefined' && window.cronitor) {
window.cronitor.track('retries_exhausted', {
totalAttempts: config.maxAttempts,
error: error instanceof Error ? error.name : 'UnknownError',
severity: 'high',
});
}
throw error;
}
// Track retry attempts in Cronitor
if (attempt > 0 && typeof window !== 'undefined' && window.cronitor) {
window.cronitor.track('retry_attempt', {
attempt: attempt + 1,
maxAttempts: config.maxAttempts,
error: error instanceof Error ? error.name : 'UnknownError',
willRetry: attempt < config.maxAttempts - 1,
});
}
// Calculate delay for next attempt
const delay = calculateBackoffDelay(attempt, config);