openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

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

Open koriyoshi2041 opened this issue 6 months ago β€’ 3 comments

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

koriyoshi2041 avatar May 30 '26 06:05 koriyoshi2041

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.

CLAassistant avatar May 30 '26 06:05 CLAassistant

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 375a4d5c830e8a1c2e78876f061330ee54787393 and a009debffe2da151ab13c1ad357a246a27949045.

πŸ“’ 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.

coderabbitai[bot] avatar May 30 '26 06:05 coderabbitai[bot]

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

koriyoshi2041 avatar May 31 '26 08:05 koriyoshi2041