mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 07:31:14 -05:00
Fix error logging and metadata
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
@@ -5,6 +6,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Copy, ExternalLink } from 'lucide-react';
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
interface Breadcrumb {
|
||||
timestamp: string;
|
||||
@@ -39,6 +41,8 @@ interface ErrorDetailsModalProps {
|
||||
}
|
||||
|
||||
export function ErrorDetailsModal({ error, onClose }: ErrorDetailsModalProps) {
|
||||
// Use breadcrumbs from error object if already fetched, otherwise they'll be empty
|
||||
const breadcrumbs = error.request_breadcrumbs || [];
|
||||
const copyErrorId = () => {
|
||||
navigator.clipboard.writeText(error.request_id);
|
||||
toast.success('Error ID copied to clipboard');
|
||||
@@ -150,9 +154,9 @@ ${error.error_stack ? `Stack Trace:\n${error.error_stack}` : ''}
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="breadcrumbs">
|
||||
{error.request_breadcrumbs && error.request_breadcrumbs.length > 0 ? (
|
||||
{breadcrumbs && breadcrumbs.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{error.request_breadcrumbs
|
||||
{breadcrumbs
|
||||
.sort((a, b) => (a.sequence_order || 0) - (b.sequence_order || 0))
|
||||
.map((crumb, index) => (
|
||||
<div key={index} className="border-l-2 border-primary pl-4 py-2">
|
||||
|
||||
@@ -2797,6 +2797,7 @@ export type Database = {
|
||||
ip_address_hash: string | null
|
||||
method: string
|
||||
parent_request_id: string | null
|
||||
referrer: string | null
|
||||
request_id: string
|
||||
request_method: string | null
|
||||
request_path: string | null
|
||||
@@ -2806,6 +2807,7 @@ export type Database = {
|
||||
session_id: string | null
|
||||
started_at: string
|
||||
status_code: number | null
|
||||
timezone: string | null
|
||||
trace_id: string | null
|
||||
user_agent: string | null
|
||||
user_id: string | null
|
||||
@@ -2823,6 +2825,7 @@ export type Database = {
|
||||
ip_address_hash?: string | null
|
||||
method: string
|
||||
parent_request_id?: string | null
|
||||
referrer?: string | null
|
||||
request_id: string
|
||||
request_method?: string | null
|
||||
request_path?: string | null
|
||||
@@ -2832,6 +2835,7 @@ export type Database = {
|
||||
session_id?: string | null
|
||||
started_at?: string
|
||||
status_code?: number | null
|
||||
timezone?: string | null
|
||||
trace_id?: string | null
|
||||
user_agent?: string | null
|
||||
user_id?: string | null
|
||||
@@ -2849,6 +2853,7 @@ export type Database = {
|
||||
ip_address_hash?: string | null
|
||||
method?: string
|
||||
parent_request_id?: string | null
|
||||
referrer?: string | null
|
||||
request_id?: string
|
||||
request_method?: string | null
|
||||
request_path?: string | null
|
||||
@@ -2858,6 +2863,7 @@ export type Database = {
|
||||
session_id?: string | null
|
||||
started_at?: string
|
||||
status_code?: number | null
|
||||
timezone?: string | null
|
||||
trace_id?: string | null
|
||||
user_agent?: string | null
|
||||
user_id?: string | null
|
||||
@@ -5578,6 +5584,28 @@ export type Database = {
|
||||
}
|
||||
Returns: undefined
|
||||
}
|
||||
| {
|
||||
Args: {
|
||||
p_breadcrumbs?: string
|
||||
p_client_version?: string
|
||||
p_duration_ms?: number
|
||||
p_endpoint?: string
|
||||
p_environment_context?: string
|
||||
p_error_message?: string
|
||||
p_error_stack?: string
|
||||
p_error_type?: string
|
||||
p_method?: string
|
||||
p_parent_request_id?: string
|
||||
p_referrer?: string
|
||||
p_request_id: string
|
||||
p_status_code?: number
|
||||
p_timezone?: string
|
||||
p_trace_id?: string
|
||||
p_user_agent?: string
|
||||
p_user_id?: string
|
||||
}
|
||||
Returns: undefined
|
||||
}
|
||||
| {
|
||||
Args: {
|
||||
p_client_version?: string
|
||||
|
||||
@@ -73,7 +73,8 @@ export async function trackRequest<T>(
|
||||
}
|
||||
: { type: 'UnknownError', message: String(error), stack: undefined };
|
||||
|
||||
// Capture breadcrumbs only (environment stored as direct columns)
|
||||
// Capture environment context and breadcrumbs
|
||||
const envContext = captureEnvironmentContext();
|
||||
const breadcrumbs = breadcrumbManager.getAll();
|
||||
|
||||
// Log error to database (fire and forget)
|
||||
@@ -92,6 +93,8 @@ export async function trackRequest<T>(
|
||||
clientVersion: context.clientVersion,
|
||||
parentRequestId: options.parentRequestId,
|
||||
traceId: context.traceId,
|
||||
timezone: envContext.timezone,
|
||||
referrer: typeof document !== 'undefined' ? document.referrer : undefined,
|
||||
}).catch(err => {
|
||||
logger.error('Failed to log error metadata', { error: err, context: 'RequestTracking' });
|
||||
});
|
||||
@@ -118,6 +121,8 @@ interface RequestMetadata {
|
||||
clientVersion?: string;
|
||||
parentRequestId?: string;
|
||||
traceId?: string;
|
||||
timezone?: string;
|
||||
referrer?: string;
|
||||
}
|
||||
|
||||
async function logRequestMetadata(metadata: RequestMetadata): Promise<void> {
|
||||
@@ -133,11 +138,13 @@ async function logRequestMetadata(metadata: RequestMetadata): Promise<void> {
|
||||
p_error_message: metadata.errorMessage ?? undefined,
|
||||
p_error_stack: metadata.errorStack ?? undefined,
|
||||
p_breadcrumbs: metadata.breadcrumbs ? JSON.stringify(metadata.breadcrumbs) : '[]',
|
||||
p_environment_context: '{}', // No longer used - environment stored as direct columns
|
||||
p_environment_context: '{}', // Legacy parameter - no longer used
|
||||
p_user_agent: metadata.userAgent ?? undefined,
|
||||
p_client_version: metadata.clientVersion ?? undefined,
|
||||
p_parent_request_id: metadata.parentRequestId ?? undefined,
|
||||
p_trace_id: metadata.traceId ?? undefined,
|
||||
p_timezone: metadata.timezone ?? undefined,
|
||||
p_referrer: metadata.referrer ?? undefined,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user