Skip to content

openai: Fix missing parse attribute on StreamWrapper #82

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 3 commits into from
May 7, 2025

Conversation

SrdjanLL
Copy link
Contributor

What does this pull request do?

  • Resolving the issue of missing parse method in StreamWrapper. The parse function from OpenAI library can be called explicitly by the user code (like litellm does here and when it happens, EDOT openai instrumentation fails because the StreamWrapper doesn't implement one and the fallback (the wrapped object) works with uninstrumented iterator.
  • This change adds parse() method to StreamWrapper and routes the parsing in the right direction depending on whether the flow is sync or async.

Testing

  1. Unit tests added to reproduce the issue and ensure it's resolved
  2. Smoke tested by instrumenting minimal reproduction example with litellm:
from litellm import completion

response = completion(
  model="openai/gpt-4o-mini",
  messages=[{ "content": "Hello, how are you?","role": "user"}],
  stream=True,
)

for event in response:
    print(event)

And confirmed we're getting the spans sent correctly. EDOT GenAI Dashboard:

image

Related issues

Closes #61

@SrdjanLL SrdjanLL requested a review from xrmx May 6, 2025 14:18
@xrmx xrmx merged commit beea9b7 into elastic:main May 7, 2025
16 checks passed
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.

OpenAIException - error - 'StreamWrapper' object has no attribute 'parse'
3 participants