Skip to content

fix: honor Agents sensitive trace setting for instructions - #1786

Closed
mikemikimike wants to merge 2 commits into
openlit:mainfrom
mikemikimike:fix-openai-agents-sensitive-instructions-1759
Closed

mikemikimike wants to merge 2 commits into
openlit:mainfrom
mikemikimike:fix-openai-agents-sensitive-instructions-1759

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

This fixes OpenAI Agents instruction capture when the SDK's default trace setting excludes sensitive data. The create_agent span now follows the SDK setting while preserving OpenLIT's capture_message_content behavior.

Regression coverage verifies the SDK setting's supported values, its enabled default, OpenLIT content suppression, and compatibility when the SDK helper is unavailable. The end-to-end reproduction uses a local mock Responses API.

Validation: focused OpenAI Agents privacy tests, focused Pylint, poetry check, and poetry build.

Issue: #1759
Fixes #1759

Summary by Sourcery

Respect the OpenAI Agents SDK privacy setting when capturing agent instructions.

Bug Fixes:

  • Honor the OpenAI Agents SDK sensitive-data tracing setting when capturing agent instructions while preserving OpenLIT content-capture controls.
  • Fail closed when the SDK sensitive-data configuration cannot be read, while retaining legacy behavior when the SDK setting is unavailable.

Tests:

  • Add regression coverage for supported SDK setting values, defaults, OpenLIT suppression, and unavailable or failing SDK configuration paths.

@sourcery-ai

sourcery-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Updates OpenAI Agents instruction capture to honor the SDK’s sensitive trace configuration without changing OpenLIT’s own content-capture behavior, with focused tests covering setting parsing, defaults, suppression, and compatibility fallback.

Sequence diagram for OpenAI Agents instruction capture privacy

sequenceDiagram
    participant Agent as Agent
    participant OpenLIT as OpenLIT instrumentation
    participant SDK as Agents SDK
    participant Span as create_agent span

    Agent->>OpenLIT: create_agent()
    OpenLIT->>SDK: _default_trace_include_sensitive_data()
    SDK-->>OpenLIT: enabled or disabled
    alt capture_message_content and sensitive trace enabled
        OpenLIT->>Span: set_attribute(instructions)
    else content capture disabled or sensitive trace disabled
        OpenLIT-->>Span: omit instructions
    end
Loading

Flow diagram for instruction capture eligibility

flowchart TD
    A[Agent instructions available] --> B{capture_message_content?}
    B -->|No| D[Do not capture instructions]
    B -->|Yes| C{SDK sensitive trace setting enabled?}
    C -->|Yes| E[Format and set span instruction attribute]
    C -->|No| D
    C -. SDK helper unavailable .-> F[Use enabled fallback]
    F --> E
Loading

File-Level Changes

Change Details Files
Gate OpenAI Agents instruction attributes on the Agents SDK sensitive-trace setting while retaining OpenLIT’s content-capture control.
  • Add a compatibility helper that reads the SDK’s sensitive-data default and falls back to enabled capture when unavailable.
  • Require both OpenLIT content capture and the SDK setting before formatting and attaching system instructions.
sdk/python/src/openlit/instrumentation/openai_agents/__init__.py
Add regression coverage for privacy-setting combinations and backward compatibility.
  • Verify supported environment-value parsing and the SDK’s enabled default.
  • Verify suppression through either the SDK setting or OpenLIT’s capture_message_content option.
  • Verify legacy capture when the SDK helper cannot be imported.
sdk/python/tests/test_openai_agents_instructions.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1759 Omit gen_ai.system_instructions from OpenAI Agents create_agent spans when the Agents SDK's global sensitive-trace setting is disabled. ✅
#1759 Preserve OpenLIT's capture_message_content behavior, including suppressing instruction capture when that setting is disabled. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="sdk/python/src/openlit/instrumentation/openai_agents/__init__.py" line_range="31-32" />
<code_context>
+    """Return the SDK default available while an Agent is being constructed."""
+    try:
+        from agents.run_config import _default_trace_include_sensitive_data
+    except ImportError:
+        return True
+
+    return _default_trace_include_sensitive_data()
</code_context>
<issue_to_address>
**Import errors enable instruction capture**

When importing `agents.run_config` raises `ImportError` for a reason other than the helper being absent, while sensitive-data capture is disabled, an `ImportError` from `agents.run_config` or one of its dependencies is treated as an unavailable helper, so the function returns `True` and captures instructions even when the SDK privacy setting is false. The caller sees sensitive instructions in the `create_agent` span.

Only use the legacy fallback when the helper is genuinely absent; otherwise fail closed and omit the instructions.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the setting is read incorrectly as enabled, system instructions—including potentially confidential rules—are attached to exported spans and can remain in telemetry after a revert. Correctly reading a disabled setting prevents that capture; reverting restores the prior unconditional capture behavior.

Blocking findings: sdk/python/src/openlit/instrumentation/openai_agents/__init__.py:32


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-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.

Sourcery assessment

Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OpenAI Agents create_agent span records the agent's instructions although the Agents SDK is set to keep sensitive data out of traces

1 participant