fix(openai-agents): resolve missing response field execution for Gene…#4320
fix(openai-agents): resolve missing response field execution for Gene…#4320Toshika-Kamble wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthrough
ChangesOpenAI Agents generation span end handling
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
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/opentelemetry/instrumentation/openai_agents/_hooks.py`:
- Around line 983-989: Surface response-extraction failures in the span closure
path instead of swallowing them in `_extract_response_attributes()` handling:
keep the try/except around the `response_source` block in `_hooks.py`, but
replace the silent `pass` with recording or logging the caught exception so the
`GenerationSpanData` fallback loss of `gen_ai.output.*` attributes is visible
while preserving non-throwing behavior.
🪄 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: 539f0ad5-5e66-495b-a467-853055d5055b
📒 Files selected for processing (1)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
| # Wrap this tightly so an internal attribute error won't abort the entire span closure | ||
| if response_source is not None: | ||
| try: | ||
| _extract_response_attributes(otel_span, response_source, trace_content) | ||
| except Exception as e: | ||
| # This keeps the span alive and lets us see if other tests pass | ||
| pass |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the relevant file and nearby symbols first.
ast-grep outline packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py --view expanded || true
# Show the target region with line numbers.
sed -n '940,1010p' packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
# Find tests touching GenerationSpanData / response extraction / response_source.
rg -n "GenerationSpanData|response_source|_extract_response_attributes|record_exception|gen_ai\.output|no response must not raise" packages/opentelemetry-instrumentation-openai-agents -g '*test*' -g '*.py'Repository: traceloop/openllmetry
Length of output: 23296
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show any tests around the suspected behavior in the package.
fd -a . packages/opentelemetry-instrumentation-openai-agents | rg 'test|tests'Repository: traceloop/openllmetry
Length of output: 4062
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py --view expanded || true
printf '\n--- FILE REGION ---\n'
sed -n '940,1010p' packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
printf '\n--- MATCHES ---\n'
rg -n "GenerationSpanData|response_source|_extract_response_attributes|record_exception|gen_ai\.output|no response must not raise" packages/opentelemetry-instrumentation-openai-agents -g '*test*' -g '*.py'Repository: traceloop/openllmetry
Length of output: 23334
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -a . packages/opentelemetry-instrumentation-openai-agents | rg 'test|tests'Repository: traceloop/openllmetry
Length of output: 4062
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py --view expanded || true
printf '\n--- FILE REGION ---\n'
sed -n '940,1010p' packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
printf '\n--- MATCHES ---\n'
rg -n "GenerationSpanData|response_source|_extract_response_attributes|record_exception|gen_ai\.output|no response must not raise" packages/opentelemetry-instrumentation-openai-agents -g '*test*' -g '*.py'Repository: traceloop/openllmetry
Length of output: 23334
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py --view expanded || true
printf '\n--- FILE REGION ---\n'
sed -n '940,1010p' packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
printf '\n--- MATCHES ---\n'
rg -n "GenerationSpanData|response_source|_extract_response_attributes|record_exception|gen_ai\.output|no response must not raise" packages/opentelemetry-instrumentation-openai-agents -g '*test*' -g '*.py'Repository: traceloop/openllmetry
Length of output: 23334
Surface response-extraction failures instead of swallowing them. _extract_response_attributes() can still fail here, and except Exception: pass will drop the GenerationSpanData fallback’s gen_ai.output.* attrs silently. Keep the non-throwing behavior, but record or log the exception instead.
🤖 Prompt for 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.
In
`@packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py`
around lines 983 - 989, Surface response-extraction failures in the span closure
path instead of swallowing them in `_extract_response_attributes()` handling:
keep the try/except around the `response_source` block in `_hooks.py`, but
replace the silent `pass` with recording or logging the caught exception so the
`GenerationSpanData` fallback loss of `gen_ai.output.*` attributes is visible
while preserving non-throwing behavior.
Description
This PR addresses an issue where
GenerationSpanDatawas missing a standaloneresponsefield, preventing_extract_response_attributesfrom executing duringon_span_end.Changes
response_source = span_datawhen handlingGenerationSpanDataif a standaloneresponseattribute is absent.Verification Results
fix(openai-agents): ....Closes 🐛 Bug Report: GenerationSpanData missing response field causes _extract_response_attributes to never execute #4157
Summary by CodeRabbit