mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 15:11:12 -05:00
Approve database migration
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { requestContext, type RequestContext } from './requestContext';
|
||||
import { breadcrumbManager } from './errorBreadcrumbs';
|
||||
import { captureEnvironmentContext } from './environmentContext';
|
||||
|
||||
export interface RequestTrackingOptions {
|
||||
endpoint: string;
|
||||
@@ -63,8 +65,16 @@ export async function trackRequest<T>(
|
||||
} catch (error: unknown) {
|
||||
const duration = Date.now() - start;
|
||||
const errorInfo = error instanceof Error
|
||||
? { type: error.name, message: error.message }
|
||||
: { type: 'UnknownError', message: String(error) };
|
||||
? {
|
||||
type: error.name,
|
||||
message: error.message,
|
||||
stack: error.stack ? error.stack.slice(0, 5000) : undefined // Limit to 5000 chars
|
||||
}
|
||||
: { type: 'UnknownError', message: String(error), stack: undefined };
|
||||
|
||||
// Capture breadcrumbs and environment
|
||||
const breadcrumbs = breadcrumbManager.getAll();
|
||||
const environment = captureEnvironmentContext();
|
||||
|
||||
// Log error to database (fire and forget)
|
||||
logRequestMetadata({
|
||||
@@ -76,6 +86,9 @@ export async function trackRequest<T>(
|
||||
duration,
|
||||
errorType: errorInfo.type,
|
||||
errorMessage: errorInfo.message,
|
||||
errorStack: errorInfo.stack,
|
||||
breadcrumbs,
|
||||
environmentContext: environment,
|
||||
userAgent: context.userAgent,
|
||||
clientVersion: context.clientVersion,
|
||||
parentRequestId: options.parentRequestId,
|
||||
@@ -100,6 +113,9 @@ interface RequestMetadata {
|
||||
duration: number;
|
||||
errorType?: string;
|
||||
errorMessage?: string;
|
||||
errorStack?: string;
|
||||
breadcrumbs?: any[];
|
||||
environmentContext?: any;
|
||||
userAgent?: string;
|
||||
clientVersion?: string;
|
||||
parentRequestId?: string;
|
||||
@@ -117,6 +133,9 @@ async function logRequestMetadata(metadata: RequestMetadata): Promise<void> {
|
||||
p_duration_ms: metadata.duration,
|
||||
p_error_type: metadata.errorType ?? undefined,
|
||||
p_error_message: metadata.errorMessage ?? undefined,
|
||||
p_error_stack: metadata.errorStack ?? undefined,
|
||||
p_breadcrumbs: metadata.breadcrumbs ? JSON.stringify(metadata.breadcrumbs) : '[]',
|
||||
p_environment_context: metadata.environmentContext ? JSON.stringify(metadata.environmentContext) : '{}',
|
||||
p_user_agent: metadata.userAgent ?? undefined,
|
||||
p_client_version: metadata.clientVersion ?? undefined,
|
||||
p_parent_request_id: metadata.parentRequestId ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user