agent-orchestrator/ui-electrobun/src/mainview/telemetry-bridge.ts
Hibryda 88206205fe feat(electrobun): multi-machine relay + OTEL telemetry
Multi-machine relay:
- relay-client.ts: WebSocket client for agor-relay with token auth,
  exponential backoff (1s-30s), TCP probe, heartbeat (15s ping)
- machines-store.svelte.ts: remote machine state tracking
- RemoteMachinesSettings.svelte: machine list, add/connect/disconnect UI
- 7 RPC types (remote.connect/disconnect/list/send/status + events)

Telemetry:
- telemetry.ts: OTEL spans + OTLP/HTTP export to Tempo,
  controlled by AGOR_OTLP_ENDPOINT env var
- telemetry-bridge.ts: tel.info/warn/error frontend convenience API
- telemetry.log RPC for frontend→Bun tracing
2026-03-22 01:46:03 +01:00

45 lines
1.3 KiB
TypeScript

/**
* Frontend telemetry bridge.
*
* Provides tel.info(), tel.warn(), tel.error() convenience methods that
* forward structured log events to the Bun process via RPC for tracing.
* No browser OTEL SDK needed (WebKitGTK incompatible).
*/
import { appRpc } from "./rpc.ts";
type LogLevel = "info" | "warn" | "error";
type Attributes = Record<string, string | number | boolean>;
function sendLog(level: LogLevel, message: string, attributes?: Attributes): void {
try {
appRpc?.request["telemetry.log"]({
level,
message,
attributes: attributes ?? {},
}).catch((err: unknown) => {
// Best-effort — never block the caller
console.warn("[tel-bridge] RPC failed:", err);
});
} catch {
// RPC not yet initialized — swallow silently
}
}
/** Frontend telemetry API. All calls are fire-and-forget. */
export const tel = {
/** Log an informational event. */
info(message: string, attributes?: Attributes): void {
sendLog("info", message, attributes);
},
/** Log a warning event. */
warn(message: string, attributes?: Attributes): void {
sendLog("warn", message, attributes);
},
/** Log an error event. */
error(message: string, attributes?: Attributes): void {
sendLog("error", message, attributes);
},
} as const;