llama-stack-mirror/tests/unit/providers/inference
Sumanth Kamenani bd35aa4d78
feat: enable streaming usage metrics for OpenAI-compatible providers (#4326)
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 WatsonX and other litellm-based providers)
- 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

Fixes #3981

Note: this work originated in PR #4200, which I closed after rebasing on
the telemetry changes. This PR rebases those commits, incorporates the
Bedrock feedback, and carries forward the same scope described there.
## Test Plan
#### OpenAIMixin + telemetry injection tests 
PYTHONPATH=src python -m pytest
tests/unit/providers/utils/inference/test_openai_mixin.py

#### LiteLLM OpenAIMixin tests
PYTHONPATH=src python -m pytest
tests/unit/providers/inference/test_litellm_openai_mixin.py -v

#### Broader inference provider
PYTHONPATH=src python -m pytest tests/unit/providers/inference/
--ignore=tests/unit/providers/inference/test_inference_client_caching.py
-v
2025-12-19 15:53:53 -08:00
..
bedrock fix: use lambda pattern for bedrock config env vars (#3307) 2025-09-05 10:45:11 +02:00
test_bedrock_adapter.py feat!: change bedrock bearer token env variable to match AWS docs & boto3 convention (#4152) 2025-11-21 09:48:05 -05:00
test_bedrock_config.py feat!: change bedrock bearer token env variable to match AWS docs & boto3 convention (#4152) 2025-11-21 09:48:05 -05:00
test_inference_client_caching.py feat!: standardize base_url for inference (#4177) 2025-11-19 08:44:28 -08:00
test_litellm_openai_mixin.py feat: enable streaming usage metrics for OpenAI-compatible providers (#4326) 2025-12-19 15:53:53 -08:00
test_openai_base_url_config.py chore: turn OpenAIMixin into a pydantic.BaseModel (#3671) 2025-10-06 11:33:19 -04:00
test_remote_vllm.py feat!: standardize base_url for inference (#4177) 2025-11-19 08:44:28 -08:00