Skip to content

feat(sdk): add trace_content parameter to Traceloop.init()#4371

Open
1123Chase1123 wants to merge 1 commit into
traceloop:mainfrom
1123Chase1123:add-trace-content-param
Open

feat(sdk): add trace_content parameter to Traceloop.init()#4371
1123Chase1123 wants to merge 1 commit into
traceloop:mainfrom
1123Chase1123:add-trace-content-param

Conversation

@1123Chase1123

@1123Chase1123 1123Chase1123 commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Adds a trace_content parameter to Traceloop.init() that lets users control whether sensitive content (prompts, completions) is sent to Traceloop via code, rather than only via the TRACELOOP_TRACE_CONTENT environment variable.

Closes #137

Changes

File Change
traceloop/sdk/__init__.py Added trace_content: Optional[bool] = None parameter + docstring
traceloop/sdk/__init__.py Parameter takes precedence over env var when explicitly set
tests/test_sdk_initialization.py 4 new test cases

Priority logic

  1. trace_content parameter (if not None) → wins
  2. TRACELOOP_TRACE_CONTENT env var → fallback
  3. Default true → backward compatible

Testing

Summary by CodeRabbit

  • New Features

    • Added a trace_content option to control whether prompts, completions, and other sensitive content are captured.
    • Explicit settings take precedence over the TRACELOOP_TRACE_CONTENT environment variable.
    • When unspecified, existing environment-based behavior remains in effect.
  • Tests

    • Added coverage for default behavior, explicit disabling, environment configuration, and override precedence.

Add a  parameter to  that controls
whether sensitive content (prompts, completions) is sent to Traceloop.

When explicitly passed, the parameter takes precedence over the
 environment variable. When omitted, it
falls back to the env var (which defaults to "true"), preserving
backward compatibility.

Closes traceloop#137
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Sage seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Traceloop.init() adds an optional trace_content parameter. Explicit values control content tracing, while omitted values use existing environment configuration. Tests cover defaults, disabling, environment handling, and explicit precedence.

Changes

Trace content control

Layer / File(s) Summary
Trace content API contract
packages/traceloop-sdk/traceloop/sdk/__init__.py
Traceloop.init() accepts and documents the optional trace_content parameter.
Trace content resolution and validation
packages/traceloop-sdk/traceloop/sdk/__init__.py, packages/traceloop-sdk/tests/test_sdk_initialization.py
Initialization prioritizes explicit values over environment configuration, with tests covering default, disabled, environment, and override cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant TraceloopInit
  participant EnvironmentConfig
  participant TracerWrapper
  Caller->>TraceloopInit: init(trace_content)
  TraceloopInit->>EnvironmentConfig: read TRACELOOP_TRACE_CONTENT when omitted
  TraceloopInit->>TracerWrapper: enable or disable content tracing
Loading

Possibly related PRs

Suggested reviewers: dvirski

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding trace_content to Traceloop.init().
Linked Issues check ✅ Passed The PR implements the requested trace_content setting, default behavior, env-var override, and tests for issue #137.
Out of Scope Changes check ✅ Passed The changes are limited to the requested SDK API, documentation, and initialization tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/traceloop-sdk/tests/test_sdk_initialization.py (1)

382-393: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use monkeypatch fixture to manage environment variables.

Pytest provides a built-in monkeypatch fixture that automatically handles restoring environment variables after the test finishes, removing the need for manual os imports and try/finally blocks.

  • packages/traceloop-sdk/tests/test_sdk_initialization.py#L382-L393: Add the monkeypatch fixture to test_trace_content_env_var_still_works and replace os.environ with monkeypatch.setenv("TRACELOOP_TRACE_CONTENT", "false").
  • packages/traceloop-sdk/tests/test_sdk_initialization.py#L395-L408: Add the monkeypatch fixture to test_trace_content_overrides_env_var and replace os.environ with monkeypatch.setenv("TRACELOOP_TRACE_CONTENT", "true").
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/traceloop-sdk/tests/test_sdk_initialization.py` around lines 382 -
393, Update test_trace_content_env_var_still_works at
packages/traceloop-sdk/tests/test_sdk_initialization.py:382-393 to accept the
monkeypatch fixture and use monkeypatch.setenv for TRACELOOP_TRACE_CONTENT,
removing the os import and manual try/finally cleanup. Apply the same fixture
and setenv changes to test_trace_content_overrides_env_var at
packages/traceloop-sdk/tests/test_sdk_initialization.py:395-408.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/traceloop-sdk/tests/test_sdk_initialization.py`:
- Around line 382-393: Update test_trace_content_env_var_still_works at
packages/traceloop-sdk/tests/test_sdk_initialization.py:382-393 to accept the
monkeypatch fixture and use monkeypatch.setenv for TRACELOOP_TRACE_CONTENT,
removing the os import and manual try/finally cleanup. Apply the same fixture
and setenv changes to test_trace_content_overrides_env_var at
packages/traceloop-sdk/tests/test_sdk_initialization.py:395-408.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 066981c5-fd83-43a5-b107-76241a3526be

📥 Commits

Reviewing files that changed from the base of the PR and between 93429cf and 37bbc26.

📒 Files selected for processing (2)
  • packages/traceloop-sdk/tests/test_sdk_initialization.py
  • packages/traceloop-sdk/traceloop/sdk/__init__.py

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.

🚀 Feature: allow disabling prompt sending as an argument to Traceloop.init()

2 participants