Skip to content

Conversation

@visheshdvivedi
Copy link

@visheshdvivedi visheshdvivedi commented Nov 2, 2025

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

Important

Add trace_content flag to Traceloop.init() to override TRACELOOP_TRACE_CONTENT env var, with tests in conftest.py.

  • Behavior:
    • Add trace_content flag to Traceloop.init() in __init__.py to control content tracing, overriding TRACELOOP_TRACE_CONTENT env var.
    • Modify enable_content_tracing logic to use trace_content flag.
  • Tests:
    • Add exporter_with_trace_content_override fixture in conftest.py to test trace_content flag overriding env var.
    • Fixture sets TRACELOOP_TRACE_CONTENT to false and initializes Traceloop with trace_content=True.
  • Misc:
    • No changes to existing functionality or other parts of the codebase.

This description was created by Ellipsis for 8d1f250. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Added a trace_content initialization parameter to allow explicit control of trace content capture behavior.
  • Tests

    • Added a new test fixture to support overriding trace content behavior during testing.

@CLAassistant
Copy link

CLAassistant commented Nov 2, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Nov 2, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new trace_content: bool = True parameter to Traceloop.init() so programmatic requests can enable content tracing regardless of environment, and adds a pytest fixture exporter_with_trace_content_override to test that override by manipulating the TracerWrapper singleton and env var.

Changes

Cohort / File(s) Summary
Test Fixture Addition
packages/traceloop-sdk/tests/conftest.py
New pytest fixture exporter_with_trace_content_override that clears/restores the TracerWrapper singleton, temporarily sets TRACELOOP_TRACE_CONTENT="false", initializes Traceloop with trace_content=True and an InMemorySpanExporter, yields the exporter, then restores state and removes the env var.
SDK Initialization Parameter
packages/traceloop-sdk/traceloop/sdk/__init__.py
Added trace_content: bool = True parameter to Traceloop.init() and changed enablement logic to enable_content_tracing = trace_content or is_content_tracing_enabled() so the parameter can override or act as a fallback to env-based detection.

Sequence Diagram

sequenceDiagram
    participant Test
    participant Env as Environment
    participant SDK as Traceloop

    Test->>Env: set TRACELOOP_TRACE_CONTENT="false"
    Test->>SDK: init(trace_content=True)
    SDK->>SDK: compute enable_content_tracing = trace_content or is_content_tracing_enabled()
    SDK->>Env: (optional) is_content_tracing_enabled() -> false
    SDK-->>Test: enable_content_tracing = True
    Note right of SDK: Tracer initialized with content tracing enabled
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review points:
    • Verify Traceloop.init() signature change is backward-compatible across call sites.
    • Confirm singleton lifecycle handling and env cleanup in the new fixture.
    • Ensure test uses/reset global tracing state safely (race conditions in parallel tests).

Poem

🐰 A little hop, a flag held high,
The env says "no", the param says "try".
trace_content=True leads the way,
A fixture checks it—hip hooray! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(traceloop-sdk): add 'trace_content' flag and relevant test cases. Fixes #137" accurately and clearly summarizes the main changes in the changeset. The title explicitly identifies both key aspects of the PR: the addition of the trace_content flag to Traceloop.init() and the corresponding test cases added to conftest.py. The title is concise, specific, and uses proper semantic commit formatting, making it immediately clear to teammates scanning history what the primary change accomplishes. The changes described in the raw_summary directly align with what the title claims, with no misleading or off-topic elements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1f250 and 136655e.

📒 Files selected for processing (1)
  • packages/traceloop-sdk/tests/conftest.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Store API keys only in environment variables/secure vaults; never hardcode secrets in code
Use Flake8 for code linting and adhere to its rules

Files:

  • packages/traceloop-sdk/tests/conftest.py
🧬 Code graph analysis (1)
packages/traceloop-sdk/tests/conftest.py (2)
packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py (1)
  • TracerWrapper (61-241)
packages/traceloop-sdk/traceloop/sdk/__init__.py (2)
  • Traceloop (37-276)
  • init (49-207)
🔇 Additional comments (1)
packages/traceloop-sdk/tests/conftest.py (1)

229-232: Good fix: prevents NameError during cleanup.

Initializing _trace_wrapper_instance = None before the conditional assignment ensures it's always defined during teardown, addressing the past review concern.


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 and usage tips.

@visheshdvivedi visheshdvivedi changed the title feat(traceloop-sdk): add 'trace_content' flag and relevant test cases feat(traceloop-sdk): add 'trace_content' flag and relevant test cases. Fixes #137 Nov 2, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 8d1f250 in 1 minute and 55 seconds. Click for details.
  • Reviewed 59 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/traceloop-sdk/traceloop/sdk/__init__.py:98
  • Draft comment:
    The expression 'trace_content or is_content_tracing_enabled()' may allow the environment variable’s value to override an explicit False. Confirm that an explicit False should not disable content tracing if the env var is truthy.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The comment is technically correct about the behavior - if trace_content=False and the environment variable is truthy, then enable_content_tracing will be True because of the or operator. However, the comment is phrased as "Confirm that..." which is explicitly against the rules. The comment is asking the author to verify/confirm their intention rather than stating that there's definitely a problem. The default value is True, so the typical use case would be someone explicitly setting it to False to disable content tracing, but the env var could override that. This could be intentional (env var takes precedence) or a bug (explicit parameter should take precedence). Without more context about the intended behavior, this is speculative. The comment identifies a real behavioral quirk in the code logic, and it's about code that was actually changed in the diff. The concern is legitimate - typically when someone explicitly passes a parameter value, they expect it to be respected rather than overridden by an environment variable. This could be a genuine bug rather than just asking for confirmation. While the behavioral concern is real, the comment is phrased as "Confirm that..." which explicitly asks the author to verify their intention. This violates the rule that says "Do NOT ask the PR author to confirm their intention, to explain, to double-check things, to ensure the behavior is intended." The comment doesn't definitively state there's a problem - it's asking for confirmation, which makes it speculative rather than actionable. The comment should be deleted because it asks the PR author to "confirm" the intended behavior rather than stating a definitive issue. While the logic concern is valid, the phrasing violates the rule against asking authors to verify their intentions.

Workflow ID: wflow_oFaevp2D8YT18FLq

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.


@pytest.fixture
def exporter_with_trace_content_override():
# Clear singleton if existed
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialize _trace_wrapper_instance to None (e.g. before the if-check) so that the teardown code doesn’t raise a NameError if the attribute isn’t present.

Suggested change
# Clear singleton if existed
_trace_wrapper_instance = None

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cf28145 and 8d1f250.

📒 Files selected for processing (2)
  • packages/traceloop-sdk/tests/conftest.py (1 hunks)
  • packages/traceloop-sdk/traceloop/sdk/__init__.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Store API keys only in environment variables/secure vaults; never hardcode secrets in code
Use Flake8 for code linting and adhere to its rules

Files:

  • packages/traceloop-sdk/traceloop/sdk/__init__.py
  • packages/traceloop-sdk/tests/conftest.py
🧬 Code graph analysis (2)
packages/traceloop-sdk/traceloop/sdk/__init__.py (1)
packages/traceloop-sdk/traceloop/sdk/config/__init__.py (1)
  • is_content_tracing_enabled (8-9)
packages/traceloop-sdk/tests/conftest.py (2)
packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py (1)
  • TracerWrapper (61-241)
packages/traceloop-sdk/traceloop/sdk/__init__.py (2)
  • Traceloop (37-276)
  • init (49-207)

del TracerWrapper.instance

# Set environment variable to false
os.environ["TRACELOOP_TRACE_CONTENT"] = "false"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Preserve the original environment variable value.

The fixture unconditionally deletes TRACELOOP_TRACE_CONTENT in cleanup, which could raise KeyError if the test deletes it, or could lose a pre-existing value set outside the test.

Apply this diff:

+    _original_trace_content = os.environ.get("TRACELOOP_TRACE_CONTENT")
     # Set environment variable to false
     os.environ["TRACELOOP_TRACE_CONTENT"] = "false"
     
     ...
     
     # Clean up environment
-    del os.environ["TRACELOOP_TRACE_CONTENT"]
+    if _original_trace_content is not None:
+        os.environ["TRACELOOP_TRACE_CONTENT"] = _original_trace_content
+    else:
+        os.environ.pop("TRACELOOP_TRACE_CONTENT", None)

Also applies to: 250-250

🤖 Prompt for AI Agents
In packages/traceloop-sdk/tests/conftest.py around lines 234 and 250, the
fixture unconditionally deletes TRACELOOP_TRACE_CONTENT in cleanup which can
raise KeyError or clobber an existing external value; capture the original
os.environ.get("TRACELOOP_TRACE_CONTENT") before setting it, and in teardown
restore it (if original is None remove safely using
os.environ.pop("TRACELOOP_TRACE_CONTENT", None) or if original had a value set
it back) so the environment is restored without raising errors or losing
pre-existing values.

sampler: Optional[Sampler] = None,
traceloop_sync_enabled: bool = False,
should_enrich_metrics: bool = True,
trace_content: bool = True,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Breaking change: default trace_content=True overrides environment variable.

The default value of True breaks backward compatibility. Previously, is_content_tracing_enabled() controlled content tracing based on the TRACELOOP_TRACE_CONTENT environment variable. Now, the OR logic at line 98 means content tracing is always enabled when callers don't pass the parameter, ignoring TRACELOOP_TRACE_CONTENT=false.

Additionally, the OR semantics prevent true programmatic override: trace_content=False cannot disable content tracing if the environment variable is set to "true", contradicting the PR objective of "explicit programmatic control."

To maintain backward compatibility and enable true override, use None as the default:

-        trace_content: bool = True,
+        trace_content: Optional[bool] = None,
         resource_attributes: dict = {},

And update the logic at line 98:

-        enable_content_tracing = trace_content or is_content_tracing_enabled()
+        enable_content_tracing = (
+            trace_content if trace_content is not None else is_content_tracing_enabled()
+        )

This ensures:

  • trace_content=True → force enable (override env var)
  • trace_content=False → force disable (override env var)
  • trace_content=None (default) → defer to env var (backward compatible)

Also applies to: 98-98

🤖 Prompt for AI Agents
In packages/traceloop-sdk/traceloop/sdk/__init__.py at line 67 and affecting
logic at line 98, the default trace_content=True both breaks backwards
compatibility and prevents programmatic overrides; change the parameter default
from True to None, and update the decision at line 98 to use the explicit value
when trace_content is not None, otherwise fall back to
is_content_tracing_enabled() (i.e., use trace_content if provided, else consult
the env-based helper), so True forces enable, False forces disable, and None
defers to the environment.

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.

2 participants