feat(diagnostics): wire @bytelyst/diagnostics-client init in ChronoMind web
This commit is contained in:
parent
2e2f3c25ca
commit
cb79c9b3ad
@ -17,6 +17,7 @@
|
||||
"@bytelyst/api-client": "file:../../learning_ai_common_plat/packages/api-client",
|
||||
"@bytelyst/auth-client": "file:../../learning_ai_common_plat/packages/auth-client",
|
||||
"@bytelyst/react-auth": "file:../../learning_ai_common_plat/packages/react-auth",
|
||||
"@bytelyst/diagnostics-client": "file:../../learning_ai_common_plat/packages/diagnostics-client",
|
||||
"@bytelyst/telemetry-client": "file:../../learning_ai_common_plat/packages/telemetry-client",
|
||||
"@serwist/next": "^9.5.6",
|
||||
"date-fns": "^4.1.0",
|
||||
|
||||
@ -5,6 +5,7 @@ import { usePathname } from 'next/navigation';
|
||||
import { AuthProvider } from '@/lib/auth-context';
|
||||
import { initTelemetry, trackPageView } from '@/lib/telemetry';
|
||||
import { initFeatureFlags } from '@/lib/feature-flags';
|
||||
import { initDiagnostics } from '@/lib/diagnostics';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export function Providers({ children }: { children: ReactNode }) {
|
||||
@ -13,6 +14,7 @@ export function Providers({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
initTelemetry();
|
||||
initFeatureFlags({ platform: 'web' });
|
||||
initDiagnostics();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
48
web/src/lib/diagnostics.ts
Normal file
48
web/src/lib/diagnostics.ts
Normal file
@ -0,0 +1,48 @@
|
||||
// ── Remote Diagnostics Client ─────────────────────────────────
|
||||
// Delegates to @bytelyst/diagnostics-client shared package.
|
||||
// Polls platform-service for active debug sessions targeting this install.
|
||||
// Privacy: only captures console logs + JS errors when a session is active.
|
||||
|
||||
import { DiagnosticsClient } from '@bytelyst/diagnostics-client';
|
||||
import { getAuthClient, PRODUCT_ID, getBaseUrl } from './auth-api';
|
||||
|
||||
function getOrCreateInstallId(): string {
|
||||
const key = `${PRODUCT_ID}_diag_install_id`;
|
||||
let id = localStorage.getItem(key);
|
||||
if (!id) {
|
||||
id =
|
||||
typeof crypto?.randomUUID === 'function'
|
||||
? crypto.randomUUID()
|
||||
: Math.random().toString(36).slice(2) + Date.now().toString(36);
|
||||
localStorage.setItem(key, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
export function initDiagnostics(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
DiagnosticsClient.getInstance({
|
||||
productId: PRODUCT_ID,
|
||||
anonymousInstallId: getOrCreateInstallId(),
|
||||
platform: 'web',
|
||||
channel: 'pwa',
|
||||
osFamily: 'unknown',
|
||||
appVersion: process.env.NEXT_PUBLIC_APP_VERSION ?? '0.1.0',
|
||||
buildNumber: process.env.NEXT_PUBLIC_BUILD_NUMBER ?? '1',
|
||||
releaseChannel: process.env.NEXT_PUBLIC_RELEASE_CHANNEL ?? 'beta',
|
||||
serverUrl: getBaseUrl(),
|
||||
getAuthToken: () => getAuthClient().getAccessToken() ?? undefined,
|
||||
captureConsole: true,
|
||||
captureErrors: true,
|
||||
captureNetwork: false,
|
||||
pollIntervalMs: 30_000,
|
||||
}).start();
|
||||
}
|
||||
|
||||
export function stopDiagnostics(): void {
|
||||
try {
|
||||
DiagnosticsClient.getInstance().stop();
|
||||
} catch {
|
||||
// not initialized
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user