Skip to content

feat(openai): Add Agents API instrumentation - #762

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit into
mainfrom
agents-api-instrument
Open

feat(openai): Add Agents API instrumentation#762
Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit into
mainfrom
agents-api-instrument

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

resolves https://linear.app/braintrustdata/issue/SDK-354/add-openai-agents-api-integration-to-python-sdk

Instruments openai.agents.sessions.create

image

Right now this has some limitations

  1. openai doesn't give us usage details consistently on it's session events, so we can't reliably attach token counts to spans 😢
  2. we don't get detailed spans about subagents

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T20:49:44.651215Z 37800a4 PR opened
ℹ️ About Codex in GitHub

Your 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

1 participant