The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Axiom from "@alchemy.run/axiom"; |
| 2 | import * as Alchemy from "alchemy"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | |
| 6 | /** Where traces and logs go. Names carry the stage, so dev, test and prod never mix. */ |
| 7 | export const Observability = Effect.gen(function* () { |
| 8 | const { stage } = yield* Alchemy.Stack; |
| 9 | const traces = yield* Axiom.Dataset("Traces", { |
| 10 | name: `shorty-${stage}-traces`, |
| 11 | kind: "otel:traces:v1", |
| 12 | }); |
| 13 | const logs = yield* Axiom.Dataset("Logs", { |
| 14 | name: `shorty-${stage}-logs`, |
| 15 | kind: "otel:logs:v1", |
| 16 | }); |
| 17 | const ingest = yield* Axiom.ApiToken("Ingest", { |
| 18 | name: `shorty-${stage}-ingest`, |
| 19 | // This token can write to these two datasets and nothing else. |
| 20 | datasetCapabilities: { |
| 21 | [`shorty-${stage}-traces`]: { ingest: ["create"] }, |
| 22 | [`shorty-${stage}-logs`]: { ingest: ["create"] }, |
| 23 | }, |
| 24 | }); |
| 25 | return { traces, logs, ingest }; |
| 26 | }); |
| 27 | |
| 28 | /** Export the Worker's spans and logs to Axiom. */ |
| 29 | export const Telemetry = Layer.unwrap( |
| 30 | Effect.gen(function* () { |
| 31 | const { traces, logs, ingest } = yield* Observability; |
| 32 | return Axiom.Telemetry({ token: ingest, traces, logs }); |
| 33 | }), |
| 34 | ); |