mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-26 23:07:02 -05:00
Connect to Lovable Cloud
Implement distributed tracing across edge functions: - Introduce span types and utilities (logger.ts enhancements) - Replace request tracking with span-based tracing in approval and rejection flows - Propagate and manage W3C trace context in edge tracking - Add span visualization scaffolding (spanVisualizer.ts) and admin TraceViewer UI (TraceViewer.tsx) - Create tracing-related type definitions and support files - Prepare RPC call logging with span context and retries
This commit is contained in:
@@ -75,11 +75,31 @@ export async function invokeWithTracking<T = any>(
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
// Generate W3C Trace Context header
|
||||
const effectiveTraceId = context.traceId || crypto.randomUUID();
|
||||
const spanId = crypto.randomUUID();
|
||||
const traceparent = `00-${effectiveTraceId}-${spanId}-01`;
|
||||
|
||||
// Add breadcrumb with trace context
|
||||
breadcrumb.apiCall(
|
||||
`/functions/${functionName}`,
|
||||
'POST',
|
||||
undefined,
|
||||
{ traceId: effectiveTraceId, spanId }
|
||||
);
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase.functions.invoke<T>(functionName, {
|
||||
body: { ...payload, clientRequestId: context.requestId },
|
||||
body: {
|
||||
...payload,
|
||||
clientRequestId: context.requestId,
|
||||
traceId: effectiveTraceId,
|
||||
},
|
||||
signal: controller.signal,
|
||||
headers: customHeaders,
|
||||
headers: {
|
||||
...customHeaders,
|
||||
'traceparent': traceparent,
|
||||
},
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
@@ -103,7 +123,15 @@ export async function invokeWithTracking<T = any>(
|
||||
}
|
||||
);
|
||||
|
||||
return { data: result, error: null, requestId, duration, attempts: attemptCount, status: 200 };
|
||||
return {
|
||||
data: result,
|
||||
error: null,
|
||||
requestId,
|
||||
duration,
|
||||
attempts: attemptCount,
|
||||
status: 200,
|
||||
traceId,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
// Handle AbortError specifically
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
|
||||
Reference in New Issue
Block a user