Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/traceloop-sdk/tests/test_sdk_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,25 @@ def probe():
del TracerWrapper.instance
if saved_instance is not None:
TracerWrapper.instance = saved_instance


def test_tracing_disabled_via_env_var_is_silent_noop(
isolated_tracer_wrapper, monkeypatch, capsys
):
"""When tracing is disabled via TRACELOOP_TRACING_ENABLED=false, init() must
mark the tracer disabled so @workflow becomes a silent no-op rather than
warning that Traceloop was never initialized (issue #4191)."""
monkeypatch.setenv("TRACELOOP_TRACING_ENABLED", "false")
try:
Traceloop.init(app_name="test")
assert TracerWrapper.verify_initialized() is False

@workflow(name="w")
def f():
return 42

capsys.readouterr() # discard init() output
assert f() == 42
assert "Traceloop not initialized" not in capsys.readouterr().out
finally:
TracerWrapper.set_disabled(False)
4 changes: 4 additions & 0 deletions packages/traceloop-sdk/traceloop/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def init(
Traceloop.__app_name = app_name

if not is_tracing_enabled():
# Mirror the `enabled=False` path: mark the tracer disabled so the
# @workflow/@task decorators become silent no-ops instead of warning
# that Traceloop was never initialized.
TracerWrapper.set_disabled(True)
print(Fore.YELLOW + "Tracing is disabled" + Fore.RESET)
return

Expand Down