Skip to content

fix(open-9027): azure openai tracer fix for chunks#597

Merged
gustavocidornelas merged 1 commit intomainfrom
siddhant/open-9027-zure-openai-tracer-not-working-when-chunks-have-no-choices
Feb 17, 2026
Merged

fix(open-9027): azure openai tracer fix for chunks#597
gustavocidornelas merged 1 commit intomainfrom
siddhant/open-9027-zure-openai-tracer-not-working-when-chunks-have-no-choices

Conversation

@shah-siddd
Copy link
Contributor

Pull Request

Summary

Fixes tracer crashes when using trace_openai with streaming on Azure OpenAI. Handles (1) stream chunks with empty choices (e.g. heartbeats) and (2) empty or invalid function-call arguments so json.loads no longer raises.

Changes

  • Empty choices: In openai_tracer.py, async_openai_tracer.py, and groq_tracer.py, streaming loops now use getattr(chunk, "choices", None) and skip chunks with no choices before accessing chunk.choices[0].delta, avoiding IndexError: list index out of range.
  • Function-call arguments: In openai_tracer.py (parse_non_streaming_output_data), async_openai_tracer.py (streaming finally blocks), and groq_tracer.py (streaming + non-streaming), only call json.loads when the arguments string is non-empty and wrap in try/except for JSONDecodeError, avoiding "Expecting value: line 1 column 1 (char 0)" on empty/invalid JSON.

Context

Azure OpenAI can send stream chunks with empty choices (e.g. heartbeat chunks) and function-call arguments can be empty or incomplete. The tracer was assuming every chunk had choices[0] and that arguments were valid JSON, which caused "Failed yield chunk. list index out of range" and "Failed to trace… Expecting value: line 1 column 1 (char 0)" when implementing the openai-chatbot template with Azure + streaming.

Testing

  • Unit tests
  • Manual testing (Azure OpenAI streaming + openai-chatbot template)
  • Postman CI/CD
  • Other (please specify)

@gustavocidornelas gustavocidornelas merged commit 5fa4e0d into main Feb 17, 2026
5 checks passed
@gustavocidornelas gustavocidornelas deleted the siddhant/open-9027-zure-openai-tracer-not-working-when-chunks-have-no-choices branch February 17, 2026 14:04
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

Comments