Skip to content

feat(traceloop-sdk): add trace_content parameter to Traceloop.init()#4367

Open
smz202000 wants to merge 1 commit into
traceloop:mainfrom
smz202000:feat/trace-content-param
Open

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

Conversation

@smz202000

@smz202000 smz202000 commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Adds a trace_content parameter to Traceloop.init() that allows users to control whether sensitive content (prompts and completions) is sent in traces.

Fixes #137

Changes

  • Modified is_content_tracing_enabled() in traceloop/sdk/config/__init__.py to accept an optional trace_content parameter. When explicitly provided, it overrides the TRACELOOP_TRACE_CONTENT environment variable. When not provided (None), it falls back to the environment variable (backward compatible).
  • Added trace_content: Optional[bool] = None parameter to Traceloop.init() in traceloop/sdk/__init__.py.
  • Added docstring documentation for the new parameter.

Usage

# Disable content tracing programmatically (overrides env var)
Traceloop.init(app_name="my-app", trace_content=False)

# Enable content tracing explicitly (overrides env var)
Traceloop.init(app_name="my-app", trace_content=True)

# Default behavior: uses TRACELOOP_TRACE_CONTENT env var
Traceloop.init(app_name="my-app")

Backward Compatibility

This change is fully backward compatible. When trace_content is not passed (the default), the existing TRACELOOP_TRACE_CONTENT environment variable behavior is preserved.

Summary by CodeRabbit

  • New Features
    • Added an optional setting to control whether prompt and completion content is included in traces.
    • Added configuration options for enabling or disabling metrics and logging.
    • Content tracing now supports explicit configuration while retaining environment-based defaults.

Add a  parameter to  that allows users
to control whether sensitive content (prompts and completions) is sent
in traces. When the parameter is not set (None), the existing
 environment variable is used (backward
compatible). When explicitly set to True or False, it overrides the
environment variable.

This addresses the feature request in issue traceloop#137, giving users more
granular control over content tracing directly from the API without
relying solely on environment variables.

Changes:
- Modified  in config to accept an
  optional  parameter that overrides the env var
- Added  parameter to

- Added docstring documentation for the new parameter
@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.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 074553ce-9efa-4b86-ae67-dd7296ee7862

📥 Commits

Reviewing files that changed from the base of the PR and between 93429cf and 0da9614.

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

📝 Walkthrough

Walkthrough

Traceloop.init() now accepts an optional trace_content override. Content tracing falls back to TRACELOOP_TRACE_CONTENT when unset, and new helpers read metrics and logging enablement from environment variables.

Changes

Trace content configuration

Layer / File(s) Summary
Configuration resolution helpers
packages/traceloop-sdk/traceloop/sdk/config/__init__.py
Content tracing supports an optional boolean override, while metrics and logging enablement are derived from their respective environment variables.
Traceloop initialization integration
packages/traceloop-sdk/traceloop/sdk/__init__.py
Traceloop.init() exposes and documents trace_content, then passes it to content-tracing configuration.

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

Suggested reviewers: dvirski

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The new metrics and logging enablement helpers are unrelated to issue #137 and appear outside the requested scope. Move the metrics/logging helpers to a separate PR or justify them in the issue scope before merging.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a trace_content parameter to Traceloop.init().
Linked Issues check ✅ Passed The PR implements the requested trace_content override for Traceloop.init() and preserves env-var fallback when unset.
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.

@GioiaZheng

Copy link
Copy Markdown

Independent privacy review against 0da96148: the SDK-level override does not currently reach the actual instrumentation gates.

I ran the same matrix against TracerWrapper.enable_content_tracing, OpenAI's should_send_prompts(), and the SDK decorator gate:

env arg SDK OpenAI/decorator
unset None true true
true False false true
false True true false
false None false false
true None true true

Minimal regression check:

monkeypatch.setenv("TRACELOOP_TRACE_CONTENT", "true")
Traceloop.init(
    exporter=InMemorySpanExporter(),
    disable_batch=True,
    trace_content=False,
)
assert TracerWrapper.enable_content_tracing is False
assert should_send_prompts() is False  # currently True

I also exercised an OpenAI chat span with an in-memory exporter and a mock HTTP transport (no provider call). With env=true, trace_content=False, the emitted openai.chat span still contained both the synthetic prompt and completion, including gen_ai.input.messages, although the SDK flag was false. The inverse conflict (env=false, trace_content=True) also leaves the instrumentation disabled.

The existing SDK privacy tests pass (29/29) because they disable content through the environment variable and therefore do not cover this split-brain case. I think this needs an end-to-end regression test at the instrumentation/span boundary before merge; changing only is_content_tracing_enabled() is not sufficient while provider instrumentations and decorators independently read TRACELOOP_TRACE_CONTENT.

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()

3 participants