chore(telemetry): add tracing headers to flush + .env.example

This commit is contained in:
saravanakumardb1 2026-02-28 02:36:55 -08:00
parent 1f18c53b76
commit 8ad31af72a
3 changed files with 19 additions and 9 deletions

5
web/.env.example Normal file
View File

@ -0,0 +1,5 @@
# ChronoMind Web — Environment Configuration
# Copy to .env.local and fill in values
# Platform Service (backend API for sync, auth, telemetry)
NEXT_PUBLIC_PLATFORM_SERVICE_URL=http://localhost:4003/api

1
web/.gitignore vendored
View File

@ -35,6 +35,7 @@ yarn-error.log*
# env files (can opt-in for committing if needed) # env files (can opt-in for committing if needed)
.env* .env*
!.env.example
# vercel # vercel
.vercel .vercel

View File

@ -121,16 +121,20 @@ export function flush(): void {
const body = JSON.stringify({ productId: PRODUCT_ID, events }); const body = JSON.stringify({ productId: PRODUCT_ID, events });
const url = `${baseUrl}/telemetry/events`; const url = `${baseUrl}/telemetry/events`;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'x-product-id': PRODUCT_ID,
'x-request-id': uuid(),
};
try { try {
const sent = navigator.sendBeacon(url, body); // sendBeacon doesn't support custom headers — use fetch with keepalive
if (!sent) { fetch(url, {
fetch(url, { method: 'POST',
method: 'POST', headers,
headers: { 'Content-Type': 'application/json' }, body,
body, keepalive: true,
keepalive: true, }).catch(() => {});
}).catch(() => {});
}
} catch { } catch {
// Best effort — telemetry is non-critical // Best effort — telemetry is non-critical
} }