[Feature] Opt-in OpenTelemetry export for metrics, traces and events
Description
Nanocoder has no way to export telemetry in a standard format. Logs go through the internal logger, and usage lives in the local /stats ledger, but there is no OpenTelemetry (OTLP) output for traces, metrics or events. A search of source/ for OpenTelemetry finds nothing.
Use Case
Teams adopting a terminal agent want to answer basic operational questions: how many sessions run per day, token and cost totals per model, tool call failure rates, p95 latency per provider, approval prompt counts, and whether a model or provider change made things worse. Codex CLI and Gemini CLI both offer OpenTelemetry export for this. Without it, nanocoder usage inside a company is invisible and cannot be compared with other tools on the same dashboards.
Proposed Solution
An opt-in nanocoder.telemetry block (disabled by default, never enabled implicitly):
exporter:none(default),otlp-http,otlp-grpcorconsole;endpointandheaderswith the existing$VARsubstitution.- Metrics: token counts (input, output, cache), cost, request latency, tool call count and duration by tool name and outcome, compaction count.
- Events or spans for: session start and end, model request, tool call, approval decision, hook run.
- A
logPromptsswitch that defaults to false. Prompt text, file paths, command lines and tool arguments are never exported unless the user turns it on, and the existing prompt scrubbing applies when they do.
Alternatives Considered
- Parse the local log and
/statsfiles with a sidecar. Fragile and not real time. - Use
/usageper session by hand. Does not aggregate across people or machines.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Implementation Notes (optional)
Most of the data already flows through source/usage/, the stats recorder in source/stats/ and the tool runtime. An exporter can subscribe to those points and load the OpenTelemetry packages lazily, so the default start-up path and the --version/--help fast paths are unchanged.
@akramcodez I’d like to take this. Could you assign it to me?
assigned @Ember452, go ahead 👍