feat(web): add client-side telemetry for API calls, errors, and scan operations

This commit is contained in:
MythEclipse
2026-06-08 01:23:51 +07:00
parent 89dcbe8fa2
commit 64dcfa70d8
3 changed files with 25 additions and 1 deletions
+6
View File
@@ -12,6 +12,7 @@ import type {
ReviewDiagnosisRequest,
DashboardSummary,
} from '@zeavis/shared';
import { recordApiCall } from './telemetry';
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? '';
@@ -21,6 +22,7 @@ export interface ApiError extends Error {
}
async function fetchApi<T>(endpoint: string, options?: RequestInit): Promise<T> {
const start = performance.now();
const url = `${apiBaseUrl}${endpoint}`;
const response = await fetch(url, {
credentials: 'include',
@@ -28,6 +30,10 @@ async function fetchApi<T>(endpoint: string, options?: RequestInit): Promise<T>
headers: options?.headers,
});
const duration = performance.now() - start;
const method = options?.method ?? 'GET';
recordApiCall(method, endpoint, duration, response.status);
if (!response.ok) {
let errorMessage = `HTTP ${response.status}`;
let source: 'uploader' | 'model-service' | 'unknown' | undefined;