Skip to content

fix(llmobs): fix parsing nontype chunk.delta in openai streamed responses #14046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ddtrace/llmobs/_integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,24 +645,24 @@ def openai_construct_message_from_streamed_chunks(streamed_chunks: List[Any]) ->
"""
message: Dict[str, Any] = {"content": "", "tool_calls": []}
for chunk in streamed_chunks:
if getattr(chunk, "usage", None):
if _get_attr(chunk, "usage", None):
message["usage"] = chunk.usage
if not hasattr(chunk, "delta"):
if not _get_attr(chunk, "delta", None):
continue
if getattr(chunk, "index", None) and not message.get("index"):
if _get_attr(chunk, "index", None) and not message.get("index"):
message["index"] = chunk.index
if getattr(chunk.delta, "role") and not message.get("role"):
if _get_attr(chunk.delta, "role", None) and not message.get("role"):
message["role"] = chunk.delta.role
if getattr(chunk, "finish_reason", None) and not message.get("finish_reason"):
if _get_attr(chunk, "finish_reason", None) and not message.get("finish_reason"):
message["finish_reason"] = chunk.finish_reason
chunk_content = getattr(chunk.delta, "content", "")
chunk_content = _get_attr(chunk.delta, "content", "")
if chunk_content:
message["content"] += chunk_content
continue
function_call = getattr(chunk.delta, "function_call", None)
function_call = _get_attr(chunk.delta, "function_call", None)
if function_call:
openai_construct_tool_call_from_streamed_chunk(message["tool_calls"], function_call_chunk=function_call)
tool_calls = getattr(chunk.delta, "tool_calls", None)
tool_calls = _get_attr(chunk.delta, "tool_calls", None)
if not tool_calls:
continue
for tool_call in tool_calls:
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-oai-resp-bug-75e91a1061a66449.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
LLM Observability, openai: This fix resolves an issue where openai tracing caused an ``AttributeError`` while parsing ``NoneType`` streamed chunk deltas.
Loading
Loading