Skip to content

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

Merged
Abhijeet Prasad (AbhiPrasad) merged 2 commits into
mainfrom
agents-api-instrument
Sep 14, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 2 commits 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 ⚠️ Failed 2026-09-14T15:27:08.855402Z 8f046bb New commits
ℹ️ 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 👍 / 👎.

Comment thread py/pyproject.toml

[tool.braintrust.matrix.openai]
latest = "openai==3.8.0"
latest = "openai==3.13.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume the goal here is to just keep bumping up latest and if/when we hit some kind of major compat issue only then do we add a new entry to the matrix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yup exactly. Every week we have a weekly job to update it. We still prefer fixed version numbers over just saying whatever is latest to prevent supply chain attacks.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 331ed80 into main Sep 14, 2026
83 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the agents-api-instrument branch September 14, 2026 16:17
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.

2 participants