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

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

Merged
ssncferreira merged 1 commit into
mainfrom
ssncf/unpriced-metric-provider-label
Aug 17, 2026
Merged

fix: label unpriced token usage metric by provider name and type#28210
ssncferreira merged 1 commit into
mainfrom
ssncf/unpriced-metric-provider-label

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Problem

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.

Changes

  • 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

Note

Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ssncferreira
ssncferreira force-pushed the ssncf/unpriced-metric-provider-label branch from 0c948bd to 230e766 Compare August 17, 2026 12:14
@linear-code

linear-code Bot commented Aug 17, 2026

Copy link
Copy Markdown

@ssncferreira
ssncferreira marked this pull request as ready for review August 17, 2026 12:22
@ssncferreira
ssncferreira requested a review from johnstcn August 17, 2026 12:22
@ssncferreira
ssncferreira merged commit 95328f1 into main Aug 17, 2026
45 checks passed
@ssncferreira
ssncferreira deleted the ssncf/unpriced-metric-provider-label branch August 17, 2026 13:08
mtojek pushed a commit that referenced this pull request Aug 17, 2026
) (#28212)

Backport of #28210

Original PR: #28210 - fix: label unpriced token usage metric by provider
name and type
Merge commit: 95328f1
Requested by: @ssncferreira
ssncferreira added a commit that referenced this pull request Aug 18, 2026
…#28220)

The cardinality notes in `aibridge/metrics/metrics.go` assume the
`provider` label takes one of three values, and two for the key pool
metrics. That was accurate when the notes were written: `provider` is
the provider instance name, and the name defaulted to one of the three
provider types aibridge supports. Instances can now be given their own
names, so the label takes any configured name and the series counts
scale with the number of configured providers rather than being capped
at a fixed number.

The monitoring docs are also updated to make clear that `provider` is
the provider instance name.

Comments and documentation only, no behaviour change.

Follow-up to #28210.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants