/** * Connects to /ws/telemetry as a user and prints what arrives, then exits. * * Exists for scripts/e2e-edge.sh, which can then assert on real frames from * the real route rather than on a mirrored composition in a unit test. Also * useful by hand: it is the quickest way to see whether a farm's telemetry is * actually reaching a console. * * Usage: bun scripts/watch-telemetry.ts [seconds] */ const [base, token, secondsArg] = process.argv.slice(2); if (!base || !token) { console.error("usage: watch-telemetry.ts [seconds]"); process.exit(2); } const seconds = Number(secondsArg ?? 15); // The token goes in the subprotocol, not the URL - a browser cannot set // headers, and a query parameter would put a bearer credential in every // access log. "bearer" first: the server echoes the first offered value back, // and the token must not be what comes back. const ws = new WebSocket(`${base}/ws/telemetry`, ["bearer", token]); const frames: unknown[] = []; ws.onmessage = (event) => { frames.push(typeof event.data === "string" ? JSON.parse(event.data) : event.data); }; ws.onerror = () => { console.error("REFUSED: the socket would not open"); process.exit(1); }; setTimeout(() => { // Printed as one JSON document so the caller can parse it rather than // scraping log lines. console.log(JSON.stringify({ negotiated: ws.protocol, frames }, null, 2)); process.exit(0); }, seconds * 1000);