fix(openai-agents): capture response.instructions as system prompt in generation spans#4131
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughPrepend agent ChangesCapture response.instructions as system message
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
Two small suggestions before merge:
Otherwise LGTM 👍 |
c2d4b1d to
465f302
Compare
|
Fixed both:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/opentelemetry-instrumentation-openai-agents/tests/test_tracing_processor.py`:
- Around line 755-884: Add a new unit test in tests/test_tracing_processor.py
that calls processor._end_generation_span with span_data.input set to a string
(e.g., "Hello") and response.instructions set to a non-empty string, calling
trace_content=True; verify that GenAIAttributes.GEN_AI_INPUT_MESSAGES is present
on the otel_span, parse the JSON, and assert the resulting messages array has
the system message (role "system" with the instruction content) followed by the
normalized user message, thereby locking in the defensive normalization behavior
in _end_generation_span.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 07b575a5-edff-46a4-a90c-1517725567ba
📒 Files selected for processing (3)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_openai_agents.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_tracing_processor.py
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/opentelemetry-instrumentation-openai-agents/tests/test_openai_agents.py
- packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
465f302 to
f2d0b22
Compare
Fixes #3738.
Problem:
When an OpenAI Agent had instructions set, the system prompt was silently dropped from generation spans — only the conversation history was recorded, with no role: system message.
Fix:
Prepend response.instructions as a role: system message to the input messages array in _end_generation_span() before passing to _extract_prompt_attributes(). Consistent with how responses_wrappers.py handles it in the plain openai instrumentation.
Summary by CodeRabbit
Bug Fixes
Tests