mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 15:11:12 -05:00
Add database persistence to 8 edge functions
Implement Phase 1 by adding error span logging and database persistence to 8 edge functions that already log errors: - detect-location - export-user-data - notify-moderators-submission - novu-webhook - send-escalation-notification - send-password-added-email - resend-deletion-code - merge-contact-tickets This update introduces startSpan/endSpan and logSpanToDatabase usage in catch blocks to ensure errors are recorded in the monitoring database.
This commit is contained in:
@@ -3,7 +3,7 @@ import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||
import { corsHeaders } from '../_shared/cors.ts';
|
||||
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
||||
import { sanitizeError } from '../_shared/errorSanitizer.ts';
|
||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||
import { edgeLogger, startRequest, endRequest, logSpanToDatabase, startSpan, endSpan } from '../_shared/logger.ts';
|
||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||
|
||||
interface ExportOptions {
|
||||
@@ -53,6 +53,11 @@ serve(withRateLimit(async (req) => {
|
||||
requestId: tracking.requestId,
|
||||
duration
|
||||
});
|
||||
|
||||
// Persist error to database
|
||||
const authErrorSpan = startSpan('export-user-data-auth-error', 'SERVER');
|
||||
endSpan(authErrorSpan, 'error', authError);
|
||||
logSpanToDatabase(authErrorSpan, tracking.requestId);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: 'Unauthorized',
|
||||
@@ -350,6 +355,11 @@ serve(withRateLimit(async (req) => {
|
||||
duration,
|
||||
error: formatEdgeError(error)
|
||||
});
|
||||
|
||||
// Persist error to database for monitoring
|
||||
const errorSpan = startSpan('export-user-data-error', 'SERVER');
|
||||
endSpan(errorSpan, 'error', error);
|
||||
logSpanToDatabase(errorSpan, tracking.requestId);
|
||||
const sanitized = sanitizeError(error, 'export-user-data');
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user