The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Axiom from "@alchemy.run/axiom"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | |
| 5 | const errors = "['chat-traces'] | where error | summarize count() by bin_auto(_time)"; |
| 6 | const chart = { id: "errors", name: "Errors", type: "TimeSeries", query: { apl: errors } } as const; |
| 7 | const window = { |
| 8 | refreshTime: 60, |
| 9 | schemaVersion: 2, |
| 10 | timeWindowStart: "qr-now-1h", |
| 11 | timeWindowEnd: "qr-now", |
| 12 | } as const; |
| 13 | const ingest = { |
| 14 | "chat-traces": { ingest: ["create"] }, |
| 15 | "chat-logs": { ingest: ["create"] }, |
| 16 | } satisfies Record<string, { ingest: "create"[] }>; |
| 17 | |
| 18 | // #region show |
| 19 | export const ObservabilityLive = Layer.unwrap( |
| 20 | Effect.gen(function* () { |
| 21 | const traces = yield* Axiom.Dataset("Traces", { name: "chat-traces", kind: "otel:traces:v1" }); |
| 22 | const logs = yield* Axiom.Dataset("Logs", { name: "chat-logs", kind: "otel:logs:v1" }); |
| 23 | const token = yield* Axiom.ApiToken("Ingest", { |
| 24 | name: "chat-ingest", |
| 25 | datasetCapabilities: ingest, |
| 26 | }); |
| 27 | // #region dashboard |
| 28 | |
| 29 | yield* Axiom.Dashboard("Dashboard", { |
| 30 | dashboard: { |
| 31 | name: "Chat", |
| 32 | owner: "", |
| 33 | charts: [chart], |
| 34 | layout: [{ i: "errors", x: 0, y: 0, w: 12, h: 6 }], |
| 35 | ...window, |
| 36 | }, |
| 37 | }); |
| 38 | // #endregion dashboard |
| 39 | // #region monitor |
| 40 | yield* Axiom.Monitor("Errors", { |
| 41 | name: "Chat errors", |
| 42 | type: "Threshold", |
| 43 | aplQuery: errors, |
| 44 | operator: "Above", |
| 45 | threshold: 10, |
| 46 | intervalMinutes: 5, |
| 47 | rangeMinutes: 5, |
| 48 | }); |
| 49 | // #endregion monitor |
| 50 | |
| 51 | return Axiom.Telemetry({ token, traces, logs }); |
| 52 | }), |
| 53 | ); |
| 54 | // #endregion show |