Skip to content

feat(tracing): add per-run capture and an OpenTelemetry processor - #6105

Merged
markstuart-oai merged 15 commits into
feat/simple-codexfrom
feature/operation-tracing
Nov 21, 2026
Merged

markstuart-oai merged 15 commits into
feat/simple-codexfrom
feature/operation-tracing

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Use one application-owned OpenTelemetry tracer provider to follow an agent run from the caller through its model calls and tool executions. A database call inside a Python tool becomes a child of that tool. When the worker resumes after approval, the new invocation attaches to its current caller and the tool span measures the actual execution.

Install openai-agents[opentelemetry] and register OpenTelemetryTracingProcessor(tracer_provider=provider). Use add_trace_processor() for dual export or set_trace_processors() to choose OTel as the only destination. The processor maps SDK spans to GenAI operations. The application controls sampling, batching, and delivery.

Choose what to capture per run through RunConfig.tracing. Every registered processor sees the same SDK spans.

operation_detail SDK model and tool spans OTel
Omitted Existing SDK-visible fields, subject to the sensitive-data setting Metadata
"metadata" Names, timings, outcomes, and available usage Metadata
"content" Submitted messages, visible output, and tool arguments and results, up to 32 KiB per direction Bounded content

trace_include_sensitive_data=False takes precedence at capture. Messages, configuration, and tool definitions share the input budget. Output has a separate budget. Detailed mode groups Runner retries of the same inference, including backoff. The default keeps per-attempt callbacks for those retries. Responses calls use response spans by default and generation spans in detailed mode.

Merge into feat/simple-codex before #6106, which uses this processor for the embedded Codex provider. The base includes #6108, #6102, and #6103. The usage guide is in draft #6107.

Test plan

  • Verified live SDK and OTel parentage during callbacks, concurrent runs, approval and resume, failures, and cancellation. Tested both Runner entry points and OTel SDK 1.45.0 and 1.45.2.
  • Tested the local shell executor through output preparation and end hooks. The tool span records the prepared result, parents instrumented work, and closes as failed or interrupted if either stage fails or is cancelled. Local shell finding
  • Checked that capture stops traversing mappings and response output lists when the byte budget fills. With a million-key dictionary, peak auxiliary allocation fell from 72 MB to 118 KB in a local probe. With 100,000 typed output items, it fell from 69 MB to 279 KB with identical retained bytes. The limit applies to captured JSON. Serializing an individual Pydantic value can still allocate in proportion to that value. Mapping finding
  • Verified the AnyLLM Responses adapter with streaming and non-streaming calls. Eight cases compare the HTTP request after extra_body overrides, the full application result, the SDK span, and OTel under the default, metadata, content, and veto policies. AnyLLM finding
  • Covered the earlier findings on Python 3.10 timestamp parsing, pre-parse limits on structured strings, capture policy on generation fields, and Chat Completions outputs with text and tool calls. Verified the shared input budget through the real adapter and a loopback endpoint.
  • Verified that a streamed resumable run applies its own capture policy before claiming its first checkpoint. A nested worker tests store saves and recovery loads under each policy, including disabled tracing, and confirms restoration of the caller's policy. Cancellation while the store saves is covered.
  • Tested media redaction with a 32,500-byte malformed URI header. A local probe measured 3.4 seconds per capture before the fix and 0.43 ms after it. The captured strings matched the original implementation across 50,000 generated inputs.
  • Confirmed that content-enabled OTel retains visible refusals as text from Responses and Chat Completions, including synthesized content-filter refusals. Both public exporter regressions failed before the fix and passed afterward. Tested the real adapters with 19 wire and omission cases across streaming and non-streaming calls, metadata, and the privacy veto. Review reply
  • Ran the full SDK verification script on the reviewed tree. Formatting, lint, mypy, and Pyright passed. Pytest passed 13,219 tests across the parallel and serial suites, with 37 skips.

Checks

  • Added regression coverage.
  • Completed independent implementation reviews.
  • Ran .agents/skills/code-change-verification/scripts/run.sh.
  • Verified the SDK capture policy and OTel export through both Runner entry points.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T03:06:25.027319Z 4ab1102 New commits
🔒 Security Review ✅ Completed 2026-11-21T03:07:45.240571Z 4ab1102 New commits

Security findings

Advisory findings (2)

ℹ️ 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 review" or "@codex security review".

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 Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 7de7610f5f

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/agents/tracing/_content.py Resolved

@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: 7de7610f5f

ℹ️ 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 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 address that feedback".

@jbeckwith-oai jbeckwith-oai 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.

Request changes. Static review and independent review confirmed the existing findings: bound JSON parsing before applying the capture budget and normalize Chat Completions output for the OpenTelemetry message projection. Please address both; I have not duplicated their inline comments.

I also found the Python 3.10 timestamp compatibility problem described in the inline comment. Reviewed capture permissions, redaction, retry grouping, approval/execution boundaries, processor context and cleanup, optional dependencies, and regression coverage. No other actionable findings.

Hosted checks: {"SKIPPED": 4, "SUCCESS": 16, "FAILURE": 3}. Python 3.10 fails the new timestamp regression (introduced in #6105); both Windows jobs still have the known UnixLocalSandbox collection failures. No candidate code or local tests were executed; the patched Codex binary was not built or run during this review.

@markstuart-oai
markstuart-oai changed the base branch from feat/simple-codex to test/simple-codex-fixtures November 20, 2026 08:57

@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: 83962e9357

ℹ️ 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 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 address that feedback".

Comment thread src/agents/tracing/span_data.py Resolved

@jbeckwith-oai jbeckwith-oai 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.

Re-reviewed the updated commit with an independent second reviewer. The Python 3.10 nanosecond timestamp issue is fixed. The earlier findings remain: bound JSON parsing before applying the capture budget and normalize Chat Completions output for the OpenTelemetry message projection. Please address both; no duplicate inline comments added. The portability changes introduce no additional finding.

Hosted check snapshot: {"SKIPPED": 6, "SUCCESS": 17, "FAILURE": 2}. Both Windows test jobs fail on existing selector-loop subprocess and Windows file-URI issues; the other 17 checks passed. Static review only; no candidate code or local tests were executed.

I also independently confirmed the additional existing capture-boundary finding: GenerationSpanData stores and exports raw input/output, and the Chat Completions adapter directly assigns converted messages and response dumps. Native processors and hosted exports therefore bypass the new bounded/redacted content policy. Apply that policy before exposing operation content to processors, while preserving legacy behavior outside the opt-in mode. This is a third outstanding finding; no duplicate inline comment added.

@jbeckwith-oai jbeckwith-oai 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.

Approved after static re-review and an independent second review. All three outstanding findings are addressed: oversized structured strings are budget-checked before JSON parsing; generation payloads are bounded/redacted or suppressed on construction and assignment before native processors and hosted export; streamed and non-streamed Chat Completions outputs now project text and tool calls correctly. The earlier Python 3.10 timestamp fix remains intact. Reviewed the capture-policy regression coverage and the accompanying Windows path/event-loop changes; no new actionable findings.

Hosted checks completed: 19 passed, 2 skipped, including both Windows test versions and the Windows packaged-contract check. No candidate code or local tests were executed.

@markstuart-oai
markstuart-oai changed the base branch from test/simple-codex-fixtures to feat/simple-codex November 21, 2026 01:43

@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: 7bb7c8130a

ℹ️ 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 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 address that feedback".

Comment thread src/agents/tracing/span_data.py Resolved

@jbeckwith-oai jbeckwith-oai 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.

Superseded by request changes: confirmed AnyLLM native Responses capture-policy gap.

Approved the updated commit after two independent static reviews. Reviewed the merge-sensitive integration with the tool preparation/output hooks, approval and cancellation span lifetimes, and the shared input/configuration/tool-definition capture budget. Capture remains opt-in with the sensitive-data veto respected, and the added regressions check that tracing does not change model requests. No actionable findings.

Hosted checks: 2 skipped, 18 success, 6 in_progress. Static review only; no candidate code or local tests executed.

@jbeckwith-oai jbeckwith-oai 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.

Request changes: supersedes my earlier approval at this commit. I missed the AnyLLM native Responses integration gap identified in the existing P2 finding; two independent static checks now confirm it. Both streaming and nonstreaming paths assign raw input and full provider responses to ResponseSpanData, whose fields have no capture-policy setter. With operation_detail="content", native processors can therefore receive oversized input and unfiltered reasoning/media despite the bounded-content policy. OpenTelemetry sanitization does not protect native processors. Route this adapter through the bounded model-capture pipeline, preserve legacy behavior when the setting is omitted, and cover both paths with native-processor regressions.

Referencing the existing finding rather than adding a duplicate inline comment. Hosted CI does not resolve this static finding. No candidate code or local tests executed.

@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: 7472be41cc

ℹ️ 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 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 address that feedback".

Comment thread src/agents/run_internal/tool_actions.py Resolved

@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 Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 7472be41cc

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/agents/tracing/_content.py Resolved

@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: 43091c5a0e

ℹ️ 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 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 address that feedback".

@jbeckwith-oai jbeckwith-oai 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.

Approved after independent static re-reviews of the current commit. The AnyLLM Responses capture gap is fixed in both streaming and nonstreaming paths, with effective submitted requests captured through the bounded model pipeline and legacy behavior preserved. Also reviewed bounded mapping traversal, visible refusal projection, local-shell finalization, and capture policy around resumable checkpoint callbacks. No remaining actionable findings in the reviewed changes.

Hosted checks: 2 skipped, 33 success. Static review only; no candidate code or local tests executed.

@markstuart-oai
markstuart-oai merged commit 6b4481c into feat/simple-codex Nov 21, 2026
37 checks passed
@markstuart-oai
markstuart-oai deleted the feature/operation-tracing branch November 21, 2026 04:52
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