Skip to content

Preserve OpenAI cost on deduplicated Agents spans - #2346

Merged
alexmojaki merged 12 commits into
mainfrom
codex/fix-openai-agents-operation-cost
Sep 4, 2026
Merged

alexmojaki merged 12 commits into
mainfrom
codex/fix-openai-agents-operation-cost

Conversation

@alexmojaki

Copy link
Copy Markdown
Contributor

Summary

  • detect when an OpenAI Agents Responses API span overlaps a Logfire-instrumented OpenAI client
  • reuse the OpenAI usage pricing calculation on the retained Agents span
  • preserve the client's base URL for provider-aware cost resolution
  • leave Agents-only spans unchanged

Tests

  • uv run pytest tests/otel_integrations/test_openai_agents.py -q
  • uv run ruff check logfire/_internal/integrations/openai_agents.py tests/otel_integrations/test_openai_agents.py
  • uv run ruff format --check logfire/_internal/integrations/openai_agents.py tests/otel_integrations/test_openai_agents.py
  • uv run pyright logfire/_internal/integrations/openai_agents.py tests/otel_integrations/test_openai_agents.py

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: ba142ff1-fab9-4769-99c6-b69300cd7873

📥 Commits

Reviewing files that changed from the base of the PR and between c9fc1ac and 5b5d458.

📒 Files selected for processing (2)
  • logfire/_internal/integrations/openai_agents.py
  • tests/otel_integrations/test_openai_agents.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Important

Approval pending

CodeRabbit has no unresolved comments, but it has not reviewed the latest commit.

Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

OpenAI Agents instrumentation now discovers the instrumented client base URL for OpenAIResponsesModel. It propagates this URL through span helpers and uses it to derive OpenAI usage attributes. Available operation.cost values are added to response span attributes. Fallback paths now return both attributes and an optional provider URL. Tests verify the provider URL and expected cost for recorded Responses API spans.

Merge Risk: ⚪ Minimal · up to 5b5d4

This localized change preserves cost calculation for deduplicated OpenAI Agents spans while leaving Agents-only spans unchanged; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: preserving OpenAI cost information on deduplicated Agents spans.
Description check ✅ Passed The description directly explains the cost preservation behavior, provider URL handling, unchanged Agents-only behavior, and validation steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-openai-agents-operation-cost

Comment @coderabbitai help to get the list of available commands.

@alexmojaki
alexmojaki enabled auto-merge September 4, 2026 13:08
@alexmojaki
alexmojaki disabled auto-merge September 4, 2026 13:13

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@alexmojaki
alexmojaki enabled auto-merge September 4, 2026 13:55
@alexmojaki
alexmojaki added this pull request to the merge queue Sep 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Merged via the queue into main with commit db2398f Sep 4, 2026
22 checks passed
@alexmojaki
alexmojaki deleted the codex/fix-openai-agents-operation-cost branch September 4, 2026 14:04
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