chore(telemetry): add tracing headers to flush + .env.example
This commit is contained in:
parent
1f18c53b76
commit
8ad31af72a
5
web/.env.example
Normal file
5
web/.env.example
Normal 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
1
web/.gitignore
vendored
@ -35,6 +35,7 @@ yarn-error.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
!.env.example
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user