Repository navigation
Description
Friction
devops_cli_ai_spend_usd_totalhas never existed in Prometheus over 60 days. It is added to only when a request's cost is non-zero, and every request was local.- Three timeseries targets without a fallback show "No data" instead of $0, which cannot be told apart from a broken pipeline: "Spend per Hour by Backend Server" (
k8s/monitoring/dashboards/ai-spend.json:577,:586) and the spend-by-server panel ink8s/monitoring/dashboards/devops-cli.json:865. - Whether a call is local (savings) or hosted (spend) is decided by the host it was sent to, never by the backend that served it. A hosted route added to the gateway would show $0 spend and count as local savings.
- A custom price override for a local model is booked as cloud spend and drops out of savings.
AISpendCollectorpublishes lifetime-ledger values under the OTLP counter names (devops_cli_ai_requests_total,devops_cli_ai_tokens_totalwithtype="total",devops_cli_ai_spend_usd_total). Nothing scrapes it today. If anything did, the dashboard's name-only sums would double requests and spend and triple tokens.- The one gateway appears under two
servervalues, its public host and its in-cluster Service, so by-server panels show it twice. - Today's values are right: every gateway route is Ollama and no override exists. This item keeps them right.
Evidence
Checked at main 3dd7fa6 (v0.2.36) on 2026-10-17, read-only.
src/devops_cli/ai/spend/ledger.py:709-710emits spend onlyif cost. The SDK counter is created on its first add (src/devops_cli/telemetry/tracer.py:1003-1018,:1063-1077).- Live: no spend series in 60 days;
litellm_spend_metric_totalalso rose 0 in 24 h. is_local(src/devops_cli/ai/spend/pricing.py:237-245, host helpers:152-234) takes server and provider only.served_byreaches the ledger column and thebackendlabel (ledger.py:675,:704) but notcalculate_request_cost(pricing.py:509-528) or_emit_local_cost_equivalent(ledger.py:611).- In
calculate_request_costthe override check (pricing.py:512) runs before the local check (:516-517). tests/test_telemetry_instruments.py:391-420pins a gateway call with an Ollamaserved_bybooked as spend when the gateway host is not configured.AISpendCollector(src/devops_cli/ai/spend/prometheus.py:76-109) is served by the non-servicedevops serve/metrics(src/devops_cli/server/routes/telemetry.py:59-84) and printed bydevops ai cost prometheus(src/devops_cli/commands/ai_cost.py:558-564).- Live 7 d: the
serverlabel holds both gateway names. fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110 changes howserveris derived (an httpx2 origin).
Remedy
Tests first, in tests/test_telemetry_instruments.py, tests/test_ai_spend_pricing.py, tests/test_ai_spend_prometheus.py and tests/test_k8s_monitoring_dashboards.py. No network:
- A local non-cached call emits one spend point of 0 next to its savings.
- Every spend timeseries target in
ai-spend.jsonanddevops-cli.jsonends inor vector(0), checked in one structural assertion over all targets. - A gateway call whose
served_byis a configured local backend counts as local even when the gateway host is not configured. One whoseserved_byis a hosted API counts as spend. With noserved_by, the host check still decides. - An override on a local server or model leaves the call in local savings.
- No metric name
AISpendCollectorexports equals anyInstrument.seriesinsrc/devops_cli/telemetry/instruments.py, and it exports notype="total"sample.
Code:
- Emit the spend counter for every non-cached request, 0 included. Add
or vector(0)to the three targets. - Pass
served_bytois_localandcalculate_request_cost, and prefer it when present. - Delete
AISpendCollectorand its/metricshookup if nothing reads them (preferred, zero-zombie rule). Otherwise rename its families todevops_cli_ai_ledger_*gauges, since they are lifetime snapshots that shrink with--days. - Use one
servervalue per configured gateway, after or within fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110's origin change. - Update
tests/test_telemetry_instruments.py:391-420to the new rule.
Key question for the owner: should a local override be recorded as a separate hardware or energy cost (proposed), or not at all.
Proposed: type/bug, P3-Low. Latent apart from three "No data" targets.
Proposed design
Problem statement
The AI spend tracking system has several issues: it only emits spend metrics for non-zero costs, leading to 'No data' displays in dashboards; it misclassifies calls as local or hosted based on the wrong server context; and the ledger exposition reuses OTLP metric names that conflict with actual instruments.
Acceptance criteria
- Criterion 1: Every request, including cached ones, emits a spend point of 0 when it's a local call
Verification: Run tests intests/test_telemetry_instruments.pyto verify local non-cached calls emit spend points with value 0 - Criterion 2: Dashboard targets for AI spend show $0 instead of 'No data' when no spend has occurred
Verification: Check that all three dashboard targets inai-spend.jsonanddevops-cli.jsonincludeor vector(0)fallbacks - Criterion 3: Gateway calls are classified correctly based on the backend they were served by, not the host that received the request
Verification: Run tests intests/test_ai_spend_pricing.pyto verify gateway calls withserved_bycorrectly determine local vs hosted status - Criterion 4: Local overrides are not recorded as cloud spend and remain in savings
Verification: Run tests intests/test_ai_spend_pricing.pyto verify that custom pricing overrides on local servers keep the call classified as local - Criterion 5: AISpendCollector does not export metric names conflicting with OTLP instruments
Verification: Verify thatAISpendCollectorexports no metrics under the same names asInstrument.seriesinsrc/devops_cli/telemetry/instruments.py
Key questions
- Should a local override be recorded as a separate hardware or energy cost?: Not at all, according to the proposed remedy. (proposed)
- Does the AISpendCollector export any metric names that conflict with OTLP instruments?: Yes, it exports metrics under names like
devops_cli_ai_requests_total,devops_cli_ai_tokens_totalanddevops_cli_ai_spend_usd_totalwhich are also used by instruments insrc/devops_cli/telemetry/instruments.py. [sources: src/devops_cli/ai/spend/prometheus.py:76-109, src/devops_cli/telemetry/instruments.py] - What determines whether a call is local or hosted?: The call's
served_byfield should be checked first, then the host ifserved_byis not present. [sources: src/devops_cli/ai/spend/pricing.py:512, src/devops_cli/ai/spend/pricing.py:516-517]
Fit
Needs splitting into 5 items:
- Fix spend series emission to include zero-cost requests
- Update dashboard targets with fallbacks for no-data cases
- Improve local/host classification logic based on served_by field
- Ensure local overrides don't count as cloud spend
- Rename or remove AISpendCollector to prevent OTLP name conflicts
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 18, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The candidate describes multiple bugs in AI spend tracking and metrics exposition.The issues affect core metrics and reporting, with incorrect data presentation and potential loss of telemetry.Fixes critical data accuracy in AI spend tracking that impacts dashboards and cost reporting.Requires changes across multiple modules including telemetry, pricing, ledger, and dashboard targets.dan-petty commentedon Oct 18, 2026
Proposal needs splitting into 5 items at 25e2cda (see proposed design in issue body).
fix(ai): embedding requests reach the spend ledger and the AI usage c…
fix(ai): the spend series exists at $0, a gateway call counts as loca…