Repository navigation
Commit 3ba999c
fix(obs): route GenAI metrics on litellm's provider, not the model prefix
Review finding from @harvhan on #523, confirmed against litellm 1.87.0 before
fixing. Reading the vendor off the model prefix was wrong in two opposite
directions, and both were silent.
**Azure was counted twice.** `azure/gpt-4o` looks like a native vendor to a
prefix reader, so this recorded it — but litellm serves azure with
`openai.AzureOpenAI` (litellm/main.py, `if custom_llm_provider == "azure"`), so
the OpenAI client instrumentor recorded it as well. The same held for every
openai-compatible provider litellm supports: groq, deepseek, xai, fireworks_ai
and ~50 others all carry a vendor prefix and all leave over the openai client.
**Bare Anthropic models were not counted at all.** `claude-sonnet-4-20250514` is
a legal litellm model string that resolves to provider `anthropic` and routes
natively, but an unprefixed name was assumed to be OpenAI, so this stood down
for an instrumentor that never saw the call.
The provider now comes from `litellm.get_llm_provider` — the same resolution
litellm uses to route — and the openai-client question from litellm's own
`openai_compatible_providers` rather than a list of ours, since that list grows
every release. Azure and four siblings are added explicitly; litellm dispatches
them over the same client without listing them there.
model before after
azure/gpt-4o (azure, False) (azure, True)
groq/llama3-8b-8192 (groq, False) (groq, True)
deepseek/deepseek-chat (deepseek, False) (deepseek, True)
claude-sonnet-4-20250514 (openai, True) (anthropic, False)
anthropic/claude-sonnet-4 unchanged
bedrock/anthropic.claude-v2 unchanged
litellm_proxy/anthropic/claude-sonnet-4 unchanged
The proxy prefix is still stripped before resolving, so a proxied call keeps
reporting the vendor underneath — the one thing the OpenAI client instrumentor
cannot report, and the reason this module exists.
Resolution is cached behind a bounded dict. Beyond speed (1.9us -> 0.09us), it
is what stops litellm's red "Provider List" banner — printed to STDOUT, not
through logging, so it cannot be filtered — appearing on every call for a model
litellm cannot place. Measured: 50 calls print it once, not 50 times.
Redirecting stdout around the lookup was the alternative and is worse; it swaps
a process-global, so under concurrency it would swallow other coroutines'
output. A plain dict rather than lru_cache because `functools.lru_cache` is
banned here (TID251) and the sanctioned one lives in `agentex._utils`, which
`agentex/lib` does not otherwise import from.
None of this touches agents without sgp-obs: `inference_call` returns the null
recorder before `_split_model` is ever reached (verified). Gateway cost on that
path, same harness back to back: 13.1us on 0.26.0, 11.9us here.
Tests: 33 in this file (was 22), 166 across the obs suites, 1714 repo-wide.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 00b738d commit 3ba999c
2 files changed
Lines changed: 192 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
43 | 76 | | |
44 | 77 | | |
45 | 78 | | |
| |||
76 | 109 | | |
77 | 110 | | |
78 | 111 | | |
79 | | - | |
| 112 | + | |
80 | 113 | | |
81 | 114 | | |
82 | 115 | | |
| 116 | + | |
| 117 | + | |
83 | 118 | | |
84 | 119 | | |
85 | | - | |
86 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
87 | 138 | | |
88 | 139 | | |
89 | 140 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
93 | 199 | | |
94 | 200 | | |
95 | 201 | | |
| |||
165 | 271 | | |
166 | 272 | | |
167 | 273 | | |
168 | | - | |
| 274 | + | |
169 | 275 | | |
| 276 | + | |
| 277 | + | |
Lines changed: 77 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
63 | 76 | | |
64 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
65 | 85 | | |
66 | 86 | | |
67 | 87 | | |
68 | 88 | | |
69 | 89 | | |
70 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
71 | 146 | | |
72 | 147 | | |
73 | 148 | | |
| |||
0 commit comments