fix: label unpriced token usage metric by provider name and type (#28210) by ssncferreira · Pull Request #28212 · coder/coder · GitHub
Skip to content

fix: label unpriced token usage metric by provider name and type (#28210) - #28212

Merged
mtojek merged 1 commit into
release/2.36from
ssncf/2.36-backport-28210
Aug 17, 2026
Merged

fix: label unpriced token usage metric by provider name and type (#28210)#28212
mtojek merged 1 commit into
release/2.36from
ssncf/2.36-backport-28210

Conversation

@ssncferreira

Copy link
Copy Markdown
Contributor

Backport of #28210

Original PR: #28210 - fix: label unpriced token usage metric by provider name and type
Merge commit: 95328f1
Requested by: @ssncferreira

)

The `provider` label was inconsistent between AI Gateway metrics. Every
metric emitted by the gateway labels `provider` with the provider
instance name, for example `anthropic-eu`, while
`coder_ai_gateway_cost_control_unpriced_token_usage_records_total` used
the provider type, for example `anthropic`. The two could not be
correlated on `provider`.

The metric was also inconsistent with itself: the path where a provider
fails to resolve labelled by instance name, and the path where a model
has no price labelled by type. The type is still worth exposing, since
prices are keyed on `(provider_type, model)` and that is what an
operator needs to add a price.

- Label the metric with `provider` (the instance name, consistent with
the other gateway metrics) and add `provider_type` (the configured type
the price is keyed on).
- Use `unknown` for `provider_type` when the provider does not resolve
to a configured type.
- Log the unresolved-provider case at `warn` instead of `info`. A
missing price is an expected steady state, but a provider that cannot be
resolved is not.
- Update the metrics docs and the `metricsdocgen` fixture.

Closes [AIGOV-574](https://linear.app/codercom/issue/AIGOV-574)

> [!NOTE]
> Initially generated by Claude Opus 5, modified and reviewed by
@ssncferreira

(cherry picked from commit 95328f1)
@github-actions

Copy link
Copy Markdown
Contributor

@ssncferreira ssncferreira added the backport/v2.36 Backport PR targeting release/2.36 label Aug 17, 2026
@ssncferreira
ssncferreira marked this pull request as ready for review August 17, 2026 13:19
@ssncferreira
ssncferreira requested a review from a team as a code owner August 17, 2026 13:19
@ssncferreira
ssncferreira requested a review from mtojek August 17, 2026 13:19
@mtojek
mtojek merged commit 83f6423 into release/2.36 Aug 17, 2026
63 of 64 checks passed
@mtojek
mtojek deleted the ssncf/2.36-backport-28210 branch August 17, 2026 13:39
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v2.36 Backport PR targeting release/2.36

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants