Fix: Improve serialization of completions/responses in Agents SDK instrumentation
Fix: Improve serialization of completions/responses in Agents SDK instrumentation
This PR fixes the serialization of completions/responses in the Agents SDK OpenTelemetry instrumentation. Instead of truncating or printing the string representation of the object, it now extracts specific fields referenced in the semconv definitions.
Changes
- Added
model_as_dict()helper function to safely convert response objects to dictionaries - Updated
_export_span()method to extract specific fields from response objects:- Model information
- Response ID
- System fingerprint
- Token usage metrics
- Completion content and metadata
- Function/tool call information
Benefits
- Increases the number of attributes from 2 to 13+ for each response
- Preserves structured data instead of truncating to string
- Maintains compatibility with different response object formats
- Follows semantic convention standards
Link to Devin run: https://app.devin.ai/sessions/480cc142d3b94f70828c01815f3622ef
This is a draft PR for exploring potential solutions to the problem.
🤖 Devin AI Engineer
I'll be helping with this pull request! Here's what you should know:
✅ I will automatically:
- Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
- Look at CI failures and help fix them
Note: I can only respond to comments from users who have write access to this repository.
⚙️ Control Options:
- [ ] Disable automatic comment and CI monitoring
Closing due to inactivity for more than 7 days.