mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -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:
@@ -2,7 +2,7 @@ import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||
import { corsHeaders } from '../_shared/cors.ts';
|
||||
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||
import { edgeLogger, startRequest, endRequest, logSpanToDatabase, startSpan, endSpan } from '../_shared/logger.ts';
|
||||
|
||||
// Apply moderate rate limiting (10 req/min) to prevent deletion code spam
|
||||
// Protects against abuse while allowing legitimate resend requests
|
||||
@@ -42,6 +42,11 @@ serve(withRateLimit(async (req) => {
|
||||
requestId: tracking.requestId,
|
||||
duration
|
||||
});
|
||||
|
||||
// Persist error to database
|
||||
const authErrorSpan = startSpan('resend-deletion-code-auth-error', 'SERVER');
|
||||
endSpan(authErrorSpan, 'error', userError);
|
||||
logSpanToDatabase(authErrorSpan, tracking.requestId);
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
@@ -165,6 +170,11 @@ serve(withRateLimit(async (req) => {
|
||||
duration,
|
||||
error: error.message
|
||||
});
|
||||
|
||||
// Persist error to database for monitoring
|
||||
const errorSpan = startSpan('resend-deletion-code-error', 'SERVER');
|
||||
endSpan(errorSpan, 'error', error);
|
||||
logSpanToDatabase(errorSpan, tracking.requestId);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: error.message,
|
||||
|
||||
Reference in New Issue
Block a user