feat(sdk): add trace_content parameter to Traceloop.init()#4371
feat(sdk): add trace_content parameter to Traceloop.init()#43711123Chase1123 wants to merge 1 commit into
Conversation
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
|
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. |
📝 WalkthroughWalkthrough
ChangesTrace content control
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/traceloop-sdk/tests/test_sdk_initialization.py (1)
382-393: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
monkeypatchfixture to manage environment variables.Pytest provides a built-in
monkeypatchfixture that automatically handles restoring environment variables after the test finishes, removing the need for manualosimports andtry/finallyblocks.
packages/traceloop-sdk/tests/test_sdk_initialization.py#L382-L393: Add themonkeypatchfixture totest_trace_content_env_var_still_worksand replaceos.environwithmonkeypatch.setenv("TRACELOOP_TRACE_CONTENT", "false").packages/traceloop-sdk/tests/test_sdk_initialization.py#L395-L408: Add themonkeypatchfixture totest_trace_content_overrides_env_varand replaceos.environwithmonkeypatch.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
📒 Files selected for processing (2)
packages/traceloop-sdk/tests/test_sdk_initialization.pypackages/traceloop-sdk/traceloop/sdk/__init__.py
Summary
Adds a
trace_contentparameter toTraceloop.init()that lets users control whether sensitive content (prompts, completions) is sent to Traceloop via code, rather than only via theTRACELOOP_TRACE_CONTENTenvironment variable.Closes #137
Changes
traceloop/sdk/__init__.pytrace_content: Optional[bool] = Noneparameter + docstringtraceloop/sdk/__init__.pytests/test_sdk_initialization.pyPriority logic
trace_contentparameter (if notNone) → winsTRACELOOP_TRACE_CONTENTenv var → fallbacktrue→ backward compatibleTesting
Summary by CodeRabbit
New Features
trace_contentoption to control whether prompts, completions, and other sensitive content are captured.TRACELOOP_TRACE_CONTENTenvironment variable.Tests