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, 07:15 UTC
| 1 | import * as Axiom from "@alchemy.run/axiom"; |
| 2 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | import * as Metric from "effect/Metric"; |
| 7 | |
| 8 | /** |
| 9 | * End-to-end fixture for Axiom telemetry: datasets and an ingest token |
| 10 | * declared next to the Worker, wired through the `Axiom.Telemetry` binding |
| 11 | * layer. Deterministic dataset names so re-runs reconcile the same |
| 12 | * datasets. |
| 13 | */ |
| 14 | export const TRACES_DATASET = "alchemy-test-otel-traces"; |
| 15 | export const LOGS_DATASET = "alchemy-test-otel-logs"; |
| 16 | export const METRICS_DATASET = "alchemy-test-otel-metrics"; |
| 17 | |
| 18 | export const Traces = Axiom.Dataset("Traces", { |
| 19 | name: TRACES_DATASET, |
| 20 | kind: "otel:traces:v1", |
| 21 | }); |
| 22 | |
| 23 | export const Logs = Axiom.Dataset("Logs", { |
| 24 | name: LOGS_DATASET, |
| 25 | kind: "otel:logs:v1", |
| 26 | }); |
| 27 | |
| 28 | export const Metrics = Axiom.Dataset("Metrics", { |
| 29 | name: METRICS_DATASET, |
| 30 | kind: "otel:metrics:v1", |
| 31 | }); |
| 32 | |
| 33 | /** Counted once per `/work` request; the test queries it out of Axiom. */ |
| 34 | const workCounter = Metric.counter("axiom_e2e_work_total"); |
| 35 | |
| 36 | export const Ingest = Axiom.ApiToken("Ingest", { |
| 37 | name: "alchemy-test-otel-ingest", |
| 38 | datasetCapabilities: { |
| 39 | [TRACES_DATASET]: { ingest: ["create"] }, |
| 40 | [LOGS_DATASET]: { ingest: ["create"] }, |
| 41 | [METRICS_DATASET]: { ingest: ["create"] }, |
| 42 | }, |
| 43 | }); |
| 44 | |
| 45 | export default class AxiomTracedWorker extends Cloudflare.Worker<AxiomTracedWorker>()( |
| 46 | "AxiomTracedWorker", |
| 47 | { |
| 48 | main: import.meta.url, |
| 49 | }, |
| 50 | Effect.gen(function* () { |
| 51 | return { |
| 52 | fetch: Effect.gen(function* () { |
| 53 | const request = yield* HttpServerRequest; |
| 54 | const url = new URL(request.url, "http://x"); |
| 55 | if (url.pathname === "/work") { |
| 56 | yield* Effect.log("axiom-work-log").pipe(Effect.withSpan("axiom.child-span")); |
| 57 | yield* Metric.update(workCounter, 1); |
| 58 | return yield* HttpServerResponse.json({ marker: "axiom-did-work" }); |
| 59 | } |
| 60 | return HttpServerResponse.text("axiom-ok"); |
| 61 | }), |
| 62 | }; |
| 63 | }).pipe( |
| 64 | // The whole observability integration: dataset endpoints + the ingest |
| 65 | // token bind onto the Worker; the built-in exporter ships each signal |
| 66 | // to its dataset, flushed per request. |
| 67 | Effect.provide( |
| 68 | Axiom.Telemetry({ |
| 69 | token: Ingest, |
| 70 | traces: Traces, |
| 71 | logs: Logs, |
| 72 | metrics: Metrics, |
| 73 | serviceName: "otel-axiom-e2e", |
| 74 | }), |
| 75 | ), |
| 76 | ), |
| 77 | ) {} |