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";
|
"use client";
|
||||||
|
|
||||||
import { DiagnosticsClient } from "@bytelyst/diagnostics-client";
|
import { createWebDiagnostics } from "@bytelyst/diagnostics-client";
|
||||||
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";
|
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||||
|
|
||||||
let started = false;
|
const { init: initDiagnostics, stop: stopDiagnostics } = createWebDiagnostics({
|
||||||
|
productId: PRODUCT_ID,
|
||||||
export function initDiagnostics() {
|
channel: "notes_web",
|
||||||
if (started) {
|
serverUrl: DIAGNOSTICS_URL,
|
||||||
return DiagnosticsClient.getInstance();
|
getAuthToken: () => {
|
||||||
}
|
if (typeof window === "undefined") return "";
|
||||||
|
|
||||||
const getAuthToken = () => {
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
||||||
};
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const client = DiagnosticsClient.getInstance({
|
export { initDiagnostics, stopDiagnostics };
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,35 +1,13 @@
|
|||||||
"use client";
|
"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";
|
import { PLATFORM_SERVICE_URL, PRODUCT_ID, TELEMETRY_TRANSPORT } from "@/lib/product-config";
|
||||||
|
|
||||||
let initialized = false;
|
const { client: telemetryClient, init: initTelemetry, trackPageView } = createWebTelemetry({
|
||||||
|
|
||||||
const telemetryClient = createTelemetryClient({
|
|
||||||
productId: PRODUCT_ID,
|
productId: PRODUCT_ID,
|
||||||
baseUrl: PLATFORM_SERVICE_URL,
|
|
||||||
endpoint: "/telemetry/events",
|
|
||||||
platform: "web",
|
|
||||||
channel: "notes_web",
|
channel: "notes_web",
|
||||||
|
baseUrl: PLATFORM_SERVICE_URL,
|
||||||
transport: TELEMETRY_TRANSPORT,
|
transport: TELEMETRY_TRANSPORT,
|
||||||
appVersion: "0.1.0",
|
|
||||||
buildNumber: "1",
|
|
||||||
releaseChannel: "dev",
|
|
||||||
osFamily: "other",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export function initTelemetry() {
|
export { telemetryClient, initTelemetry, trackPageView };
|
||||||
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 };
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user