Skip to content

fix: mark tracer disabled when tracing is disabled via env var#4203

Open
koriyoshi2041 wants to merge 1 commit into
traceloop:mainfrom
koriyoshi2041:fix/env-disabled-tracing-noop
Open

fix: mark tracer disabled when tracing is disabled via env var#4203
koriyoshi2041 wants to merge 1 commit into
traceloop:mainfrom
koriyoshi2041:fix/env-disabled-tracing-noop

Conversation

@koriyoshi2041
Copy link
Copy Markdown

@koriyoshi2041 koriyoshi2041 commented May 30, 2026

Fixes #4191.

There are two ways to disable tracing, and they diverge:

  • Traceloop.init(enabled=False) calls TracerWrapper.set_disabled(True) and returns, so @workflow/@task decorators become clean no-ops (verify_initialized() returns False early when disabled).
  • TRACELOOP_TRACING_ENABLED=false just prints "Tracing is disabled" and returns without set_disabled(True).

So with the env var, TracerWrapper is never initialized and never marked disabled. Decorated functions then hit the uninitialized branch and spam Warning: Traceloop not initialized, make sure you call Traceloop.init().

The fix calls TracerWrapper.set_disabled(True) in the env-var path too, mirroring the enabled=False branch.

Added test_tracing_disabled_via_env_var_is_silent_noop (in test_sdk_initialization.py): with TRACELOOP_TRACING_ENABLED=false, after init() a @workflow-decorated call must not print the "not initialized" warning. It fails before the fix and passes after.

(The issue title says TRACELOOP_TRACKING_ENABLED, but the actual env var is TRACELOOP_TRACING_ENABLED — the behavior is the same regardless.)

Summary by CodeRabbit

  • Bug Fixes

    • Fixed SDK to operate silently when tracing is disabled via configuration, preventing unnecessary warnings from decorated functions.
  • Tests

    • Added test to verify that disabled tracing state allows decorated functions to execute as silent no-ops without initialization warnings.

Review Change Stack

Traceloop.init() returns early when TRACELOOP_TRACING_ENABLED is false, but
unlike the enabled=False init flag it never called
TracerWrapper.set_disabled(True). The TracerWrapper was therefore left
uninitialized rather than disabled, so @workflow/@task decorators printed
"Traceloop not initialized" warnings instead of running as silent no-ops.
Mirror the init-flag path and mark the tracer disabled.
@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
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2927bda3-c5ca-43b5-ae4b-2a6237cd3c17

📥 Commits

Reviewing files that changed from the base of the PR and between 375a4d5 and a009deb.

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

📝 Walkthrough

Walkthrough

When tracing is disabled via the TRACELOOP_TRACING_ENABLED environment variable, Traceloop.init() now calls TracerWrapper.set_disabled(True) before returning. This ensures decorated functions become silent no-ops without emitting initialization warnings, matching the behavior of the enabled=False parameter.

Changes

Disabled Tracing Silent No-op Behavior

Layer / File(s) Summary
Tracer disabled flag on environment-based disablement
packages/traceloop-sdk/traceloop/sdk/__init__.py
Traceloop.init() calls TracerWrapper.set_disabled(True) when tracing is disabled via environment configuration, before printing the "Tracing is disabled" message.
Silent no-op behavior validation
packages/traceloop-sdk/tests/test_sdk_initialization.py
New test test_tracing_disabled_via_env_var_is_silent_noop verifies that TRACELOOP_TRACING_ENABLED=false with Traceloop.init() makes the tracer uninitialized and causes @workflow-decorated functions to execute without warnings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A silent hop through tracing's way,
Where disabled flags now have their say,
No warnings logged, no errors shown,
Just quiet paths where they've been sown.
Decorators rest in peaceful state,
When disabled at the gate! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix: mark tracer disabled when tracing is disabled via env var' accurately summarizes the main change: calling TracerWrapper.set_disabled(True) in the env-var disable path to match the enabled=False behavior.
Linked Issues check ✅ Passed The PR fully addresses issue #4191 by making the env-var disable path call TracerWrapper.set_disabled(True) to mirror init(enabled=False) behavior, eliminating the spurious 'not initialized' warnings.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the inconsistency between env-var and init flag disable paths; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

@koriyoshi2041
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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.

🐛 Bug Report: TRACELOOP_TRACING_ENABLED does not match Traceloop.init(enabled) parameter behavior

2 participants