Fix span duplicates and metrics

Implements complete plan to resolve duplicate span_id issues and metric collection errors:
- Ensure edge handlers return proper Response objects to prevent double logging
- Update collect-metrics to use valid metric categories, fix system_alerts query, and adjust returns
- Apply detect-anomalies adjustments if needed and add defensive handling in wrapper
- Prepare ground for end-to-end verification of location-related fixes
This commit is contained in:
gpt-engineer-app[bot]
2025-11-12 04:57:54 +00:00
parent b6d1b99f2b
commit 5531376edf
3 changed files with 39 additions and 19 deletions

View File

@@ -266,7 +266,15 @@ export function wrapEdgeFunction(
logSpanToDatabase(span, requestId);
// Clone response to add tracking headers
const responseBody = await response.text();
// Defensive check: ensure handler returned a Response object
let responseBody: string;
if (response instanceof Response) {
responseBody = await response.text();
} else {
// Handler returned non-Response (shouldn't happen, but handle it)
addSpanEvent(span, 'warning_non_response_object');
responseBody = JSON.stringify(response);
}
const enhancedResponse = new Response(responseBody, {
status: response.status,
statusText: response.statusText,