Commit 7c05120
committed
Enable streaming usage metrics for OpenAI-compatible providers
Inject stream_options={"include_usage": True} when streaming and OpenTelemetry
telemetry is active. Telemetry always overrides any caller preference to ensure
complete and consistent observability metrics.
Changes:
- Add conditional stream_options injection to OpenAIMixin (benefits OpenAI,
Bedrock, Runpod, Together, Fireworks providers)
- Add conditional stream_options injection to LiteLLMOpenAIMixin (benefits
litellm-based providers that call parent methods)
- Add telemetry-gated stream_options injection to WatsonX via helper method
(WatsonX bypasses LiteLLMOpenAIMixin by calling litellm.acompletion directly,
so it uses _inject_stream_options_for_telemetry helper to avoid code duplication)
- Check telemetry status using trace.get_current_span().is_recording()
- Override include_usage=False when telemetry active to prevent metric gaps
- Unit tests for this functionality
- Remove legacy ungated stream_options from Bedrock and Runpod providers
(pre-#4127 code that bypassed telemetry gating)
Fixes #39811 parent ff375f1 commit 7c05120
7 files changed
Lines changed: 435 additions & 44 deletions
File tree
- src/llama_stack/providers
- remote/inference
- bedrock
- runpod
- watsonx
- utils/inference
- tests/unit/providers
- inference
- utils/inference
Lines changed: 1 addition & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 84 | + | |
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
| |||
Lines changed: 0 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | 7 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 8 | | |
16 | 9 | | |
17 | 10 | | |
| |||
29 | 22 | | |
30 | 23 | | |
31 | 24 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
Lines changed: 46 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 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 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
50 | 84 | | |
51 | 85 | | |
52 | 86 | | |
| |||
55 | 89 | | |
56 | 90 | | |
57 | 91 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
66 | 97 | | |
67 | 98 | | |
68 | 99 | | |
| |||
183 | 214 | | |
184 | 215 | | |
185 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
186 | 223 | | |
187 | 224 | | |
188 | 225 | | |
| |||
199 | 236 | | |
200 | 237 | | |
201 | 238 | | |
202 | | - | |
| 239 | + | |
203 | 240 | | |
204 | 241 | | |
205 | 242 | | |
| |||
Lines changed: 26 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
182 | 196 | | |
183 | 197 | | |
184 | 198 | | |
| |||
201 | 215 | | |
202 | 216 | | |
203 | 217 | | |
204 | | - | |
| 218 | + | |
205 | 219 | | |
206 | 220 | | |
207 | 221 | | |
| |||
216 | 230 | | |
217 | 231 | | |
218 | 232 | | |
219 | | - | |
220 | | - | |
| 233 | + | |
221 | 234 | | |
222 | 235 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
227 | 246 | | |
228 | 247 | | |
229 | 248 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
274 | 288 | | |
275 | 289 | | |
276 | 290 | | |
| |||
308 | 322 | | |
309 | 323 | | |
310 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
311 | 339 | | |
312 | 340 | | |
313 | 341 | | |
| |||
0 commit comments