feat(openai): Add Agents API instrumentation - #762
feat(openai): Add Agents API instrumentation#762Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37800a4a54
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| finally: | ||
| trace.finish() | ||
|
|
||
| return _TracedStream(stream, gen(), trace.finish) |
There was a problem hiding this comment.
Preserve raw-response parsing for Agents streams
When callers use sessions.with_raw_response.create(..., stream=True) (or the streaming-response helper), OpenAI injects the raw-response header, so self.create_fn returns a raw response rather than an iterable event stream. Wrapping that object directly means raw.parse() is merely delegated to the underlying response and returns the original untraced stream; consuming it bypasses trace.observe() and can leave the task span open. Detect _raw_response_requested(kwargs), parse the raw response for instrumentation, and return a _RawResponseWithTracedStream as the chat/Responses wrappers do; the async path has the same defect.
Useful? React with 👍 / 👎.
resolves https://linear.app/braintrustdata/issue/SDK-354/add-openai-agents-api-integration-to-python-sdk
Instruments
openai.agents.sessions.createRight now this has some limitations
usagedetails consistently on it's session events, so we can't reliably attach token counts to spans 😢