fix: mark tracer disabled when tracing is disabled via env var
Fixes #4191.
There are two ways to disable tracing, and they diverge:
Traceloop.init(enabled=False)callsTracerWrapper.set_disabled(True)and returns, so@workflow/@taskdecorators become clean no-ops (verify_initialized()returnsFalseearly when disabled).TRACELOOP_TRACING_ENABLED=falsejust prints"Tracing is disabled"and returns withoutset_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.
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.
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.pypackages/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.
Comment @coderabbitai help to get the list of available commands and usage tips.
I have read the CLA Document and I hereby sign the CLA