Skip to content

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