refactor(web): migrate telemetry + diagnostics to createWebTelemetry/createWebDiagnostics
- telemetry.ts: 35 → 13 lines via createWebTelemetry() - diagnostics.ts: 43 → 16 lines via createWebDiagnostics() - 14/14 web tests pass, typecheck clean
This commit is contained in:
parent
21ad6ed978
commit
4a5a782333
@ -1,43 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import { DiagnosticsClient } from "@bytelyst/diagnostics-client";
|
||||
import { createWebDiagnostics } from "@bytelyst/diagnostics-client";
|
||||
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
let started = false;
|
||||
|
||||
export function initDiagnostics() {
|
||||
if (started) {
|
||||
return DiagnosticsClient.getInstance();
|
||||
}
|
||||
|
||||
const getAuthToken = () => {
|
||||
if (typeof window === "undefined") {
|
||||
return "";
|
||||
}
|
||||
|
||||
const { init: initDiagnostics, stop: stopDiagnostics } = createWebDiagnostics({
|
||||
productId: PRODUCT_ID,
|
||||
channel: "notes_web",
|
||||
serverUrl: DIAGNOSTICS_URL,
|
||||
getAuthToken: () => {
|
||||
if (typeof window === "undefined") return "";
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const client = DiagnosticsClient.getInstance({
|
||||
productId: PRODUCT_ID,
|
||||
anonymousInstallId: `${PRODUCT_ID}-web-install`,
|
||||
platform: "web",
|
||||
channel: "notes_web",
|
||||
osFamily: "macos",
|
||||
appVersion: "0.1.0",
|
||||
buildNumber: "1",
|
||||
releaseChannel: "dev",
|
||||
serverUrl: DIAGNOSTICS_URL,
|
||||
getAuthToken,
|
||||
pollIntervalMs: 30000,
|
||||
captureConsole: false,
|
||||
captureErrors: true,
|
||||
captureNetwork: false,
|
||||
});
|
||||
|
||||
client.start().catch(() => {
|
||||
// Diagnostics is best-effort during scaffold phase.
|
||||
});
|
||||
started = true;
|
||||
return client;
|
||||
}
|
||||
export { initDiagnostics, stopDiagnostics };
|
||||
|
||||
@ -1,35 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { createTelemetryClient } from "@bytelyst/telemetry-client";
|
||||
import { createWebTelemetry } from "@bytelyst/telemetry-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID, TELEMETRY_TRANSPORT } from "@/lib/product-config";
|
||||
|
||||
let initialized = false;
|
||||
|
||||
const telemetryClient = createTelemetryClient({
|
||||
const { client: telemetryClient, init: initTelemetry, trackPageView } = createWebTelemetry({
|
||||
productId: PRODUCT_ID,
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
endpoint: "/telemetry/events",
|
||||
platform: "web",
|
||||
channel: "notes_web",
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
transport: TELEMETRY_TRANSPORT,
|
||||
appVersion: "0.1.0",
|
||||
buildNumber: "1",
|
||||
releaseChannel: "dev",
|
||||
osFamily: "other",
|
||||
});
|
||||
|
||||
export function initTelemetry() {
|
||||
if (initialized) return telemetryClient;
|
||||
telemetryClient.init();
|
||||
telemetryClient.trackEvent("info", "app_shell", "web_app_initialized");
|
||||
initialized = true;
|
||||
return telemetryClient;
|
||||
}
|
||||
|
||||
export function trackPageView(page: string) {
|
||||
telemetryClient.trackEvent("info", "navigation", "page_view", {
|
||||
feature: page,
|
||||
});
|
||||
}
|
||||
|
||||
export { telemetryClient };
|
||||
export { telemetryClient, initTelemetry, trackPageView };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user