Skip to content

Feature: Make trace_include_sensitive_data configurable via environment variable #1192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Kunmeer-SyedMohamedHyder
Copy link
Contributor

@Kunmeer-SyedMohamedHyder Kunmeer-SyedMohamedHyder commented Jul 19, 2025

Description:

This PR adds support for configuring trace_include_sensitive_data in RunConfig using an environment variable: OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA.

Previously, this field always defaulted to True, and there was no way to control it without explicitly passing it into RunConfig. With this change, if the field is not set explicitly, its value will be pulled from the environment. This provides more flexibility, especially in environments where trace sensitivity and data privacy are important.

The environment variable supports common boolean values like true, false, 1, 0, yes, and no (case-insensitive).

Fixes #1183

Behavior Summary:

  • If trace_include_sensitive_data is passed explicitly, that value is used.
  • Otherwise, the value defaults based on the OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA environment variable.
  • If the environment variable is not set, it falls back to True (preserving current behavior).

Example usage:

export OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA=false
config = RunConfig()  # trace_include_sensitive_data will be False

config = RunConfig(trace_include_sensitive_data=True)  # Explicit override, will be True

@Kunmeer-SyedMohamedHyder Kunmeer-SyedMohamedHyder changed the title Feature: Load trace_include_sensitive_data from an environment variable Feature: Make trace_include_sensitive_data configurable via environment variable Jul 19, 2025
@seratch seratch added enhancement New feature or request feature:core labels Jul 22, 2025
Copy link
Contributor

github-actions bot commented Aug 1, 2025

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions bot added the stale label Aug 1, 2025
@seratch seratch added skip-stale and removed stale labels Aug 1, 2025
@loiccordone
Copy link

Thank you for the PR @Kunmeer-SyedMohamedHyder , any blocking points before approving it @seratch?
Thanks all

@seratch seratch requested review from seratch and Copilot August 15, 2025 02:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds environment variable configuration for the trace_include_sensitive_data field in RunConfig. Previously, this field was hardcoded to True, but now it can be controlled via the OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA environment variable while maintaining backward compatibility.

  • Introduces a new helper function _default_trace_include_sensitive_data() to parse the environment variable
  • Changes trace_include_sensitive_data from a simple default value to use field(default_factory=...)
  • Adds comprehensive test coverage for various boolean string formats and precedence behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/agents/run.py Implements environment variable parsing logic and updates RunConfig field definition
tests/test_run_config.py Adds test cases for environment variable parsing, default behavior, and explicit override precedence

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

def _default_trace_include_sensitive_data() -> bool:
"""Returns the default value for trace_include_sensitive_data based on environment variable."""
val = os.getenv("OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA", "true")
return val.strip().lower() in ("1", "true", "yes", "on")
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The boolean parsing logic is incomplete and will incorrectly handle invalid values. For example, setting the environment variable to "invalid" will return False, but it should either raise an error or have documented fallback behavior. Consider adding validation or explicit handling for unrecognized values.

Suggested change
return val.strip().lower() in ("1", "true", "yes", "on")
val = os.getenv("OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA", "true").strip().lower()
truthy = ("1", "true", "yes", "on")
falsy = ("0", "false", "no", "off")
if val in truthy:
return True
elif val in falsy:
return False
else:
raise ValueError(
f"Invalid value for OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA: '{val}'. "
f"Expected one of {truthy + falsy}."
)

Copilot uses AI. Check for mistakes.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

I think having this enhancement is good; @rm-openai any thoughts?

@seratch seratch requested a review from rm-openai August 15, 2025 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for global or environment-based default for trace_include_sensitive_data in RunConfig
4 participants