Skip to content

feat: add client label to InterceptionCount, PromptCount and TokenUseCount metrics#209

Merged
pawbana merged 2 commits intomainfrom
pb/metrics-add-client-label
Mar 10, 2026
Merged

feat: add client label to InterceptionCount, PromptCount and TokenUseCount metrics#209
pawbana merged 2 commits intomainfrom
pb/metrics-add-client-label

Conversation

@pawbana
Copy link
Contributor

@pawbana pawbana commented Mar 9, 2026

No description provided.

Copy link
Contributor Author

pawbana commented Mar 9, 2026

@pawbana pawbana force-pushed the pb/metrics-add-client-label branch 2 times, most recently from e928b2c to 24bcf05 Compare March 9, 2026 16:37
@pawbana pawbana marked this pull request as ready for review March 9, 2026 16:38
Copy link
Collaborator

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM 👍 just a comment about initiator_id, but it is not directly related to the changes in this PR.

// Interception-related metrics.

// Pessimistic cardinality: 2 providers, 5 models, 2 statuses, 2 routes, 3 methods = up to 120 PER INITIATOR.
// Pessimistic cardinality: 3 providers, 5 models, 2 statuses, 2 routes, 3 methods, 10 clients = up to 1800 PER INITIATOR.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it 3 routes? 👀

  • Anthropic: /v1/messages
  • OpenAI/Copilot: /chat/completions, /responses
Suggested change
// Pessimistic cardinality: 3 providers, 5 models, 2 statuses, 2 routes, 3 methods, 10 clients = up to 1800 PER INITIATOR.
// Pessimistic cardinality: 3 providers, 5 models, 2 statuses, 3 routes, 3 methods, 10 clients = up to 1800 PER INITIATOR.

Help: "The count of intercepted requests.",
}, append(baseLabels, "status", "route", "method", "initiator_id")),
// Pessimistic cardinality: 2 providers, 5 models, 2 routes = up to 20.
}, append(baseLabels, "status", "route", "method", "initiator_id", "client")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not directly related to the changes in this PR, but is using initiator_id as a label a good idea? cc @dannykopping
It's an unbounded value and the main factor of label cardinality (as the comments themselves mention). For 10k users, InterceptionCount alone could produce up to 18M time series. Maybe this is something that was already discussed, and we are still far from those numbers, but just pointing this out.

The Prometheus docs explicitly recommend against using user IDs as labels.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided that the benefit of operators being able to quickly identify which initiator(s) were overloading the system outweighed the possible cardinality problem. If cardinality becomes a problem they can just drop that label.

expectModel: "claude-sonnet-4-0",
expectRoute: "/v1/messages",
expectProvider: config.ProviderAnthropic,
expectClient: aibridge.ClientUnknown,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be worth adding a couple more test cases with different user agents (e.g. Copilot, Cursor) to cover label propagation beyond just Claude Code and Unknown.

@pawbana pawbana force-pushed the pb/testing-cleanup-new-request-bridge branch from b24c6fc to 0f25518 Compare March 10, 2026 11:37
@pawbana pawbana force-pushed the pb/metrics-add-client-label branch from 24bcf05 to c92a71f Compare March 10, 2026 11:37
@pawbana pawbana changed the base branch from pb/testing-cleanup-new-request-bridge to graphite-base/209 March 10, 2026 12:16
@pawbana pawbana force-pushed the graphite-base/209 branch from 0f25518 to b01456d Compare March 10, 2026 12:31
@pawbana pawbana force-pushed the pb/metrics-add-client-label branch from c92a71f to 59973a3 Compare March 10, 2026 12:31
@pawbana pawbana changed the base branch from graphite-base/209 to main March 10, 2026 12:31
Copy link
Contributor Author

pawbana commented Mar 10, 2026

Merge activity

  • Mar 10, 12:56 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 10, 12:56 PM UTC: @pawbana merged this pull request with Graphite.

@pawbana pawbana merged commit 250e790 into main Mar 10, 2026
3 checks passed
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.

3 participants