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*
!.env.example
# vercel
.vercel

View File

@ -121,16 +121,20 @@ export function flush(): void {
const body = JSON.stringify({ productId: PRODUCT_ID, 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 {
const sent = navigator.sendBeacon(url, body);
if (!sent) {
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
keepalive: true,
}).catch(() => {});
}
// sendBeacon doesn't support custom headers — use fetch with keepalive
fetch(url, {
method: 'POST',
headers,
body,
keepalive: true,
}).catch(() => {});
} catch {
// Best effort — telemetry is non-critical
}