Skip to content

fix: remove incorrect await on async generator in Groq streaming#3947

Open
muhammadrashid4587 wants to merge 1 commit intotraceloop:mainfrom
muhammadrashid4587:fix/groq-async-streaming-await
Open

fix: remove incorrect await on async generator in Groq streaming#3947
muhammadrashid4587 wants to merge 1 commit intotraceloop:mainfrom
muhammadrashid4587:fix/groq-async-streaming-await

Conversation

@muhammadrashid4587
Copy link
Copy Markdown

@muhammadrashid4587 muhammadrashid4587 commented Apr 5, 2026

Summary

  • Removes erroneous await keyword when returning _create_async_stream_processor() in the Groq async instrumentation path
  • _create_async_stream_processor is an async generator (uses yield), so await-ing it raises TypeError: object async_generator can't be used in 'await' expression
  • This completely breaks async streaming with Groq instrumentation

Root Cause

Line 355 had return await _create_async_stream_processor(response, span, event_logger) but the function is an async generator, not a coroutine. The sync counterpart on line 272 correctly uses return _create_stream_processor(...) without await.

The same pattern is handled correctly in the Ollama and MistralAI instrumentation packages.

Changes

  • packages/opentelemetry-instrumentation-groq/.../groq/__init__.py — removed await from the return statement

Test Plan

  • Verify async streaming with Groq no longer raises TypeError
  • Verify sync streaming still works correctly
  • Verify telemetry spans are properly recorded for async streaming

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming response handling in Groq instrumentation to properly process streamed data while maintaining error handling and distributed tracing capabilities.

_create_async_stream_processor is an async generator (uses yield),
so it cannot be awaited. Awaiting it raises:
  TypeError: object async_generator can't be used in 'await' expression

The sync counterpart (_create_stream_processor) correctly returns
without await on line 272. This fix makes the async path consistent.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9ba8655-a005-4a80-b9d0-9d68f1b018c6

📥 Commits

Reviewing files that changed from the base of the PR and between 0a25803 and 9d25dc7.

📒 Files selected for processing (1)
  • packages/opentelemetry-instrumentation-groq/opentelemetry/instrumentation/groq/__init__.py

📝 Walkthrough

Walkthrough

The async wrapper in the groq instrumentation was modified to return the async stream processor directly instead of awaiting it, adjusting the control flow for streaming responses while maintaining existing exception handling and span lifecycle management.

Changes

Cohort / File(s) Summary
Async Stream Processing
packages/opentelemetry-instrumentation-groq/opentelemetry/instrumentation/groq/__init__.py
Removed await from the streaming-response return path in _awrap, now returning the async generator/iterable directly instead of awaiting the processor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A stream flows swift without the wait,
Async magic at the gate,
No await to slow its gleaming pace,
The rabbit grins with newfound grace!
🌊✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing an incorrect await statement from an async generator in Groq streaming instrumentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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