Fix telemetry implementation based on PR feedback

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-08 07:22:14 +00:00
parent 04304f236c
commit c9cfe0a208
3 changed files with 53 additions and 36 deletions

View File

@@ -6,18 +6,20 @@ import pytest
from crewai.telemetry import Telemetry
def test_telemetry_disabled_with_otel_sdk_disabled():
"""Test that telemetry is disabled when OTEL_SDK_DISABLED is set to true."""
with patch.dict(os.environ, {"OTEL_SDK_DISABLED": "true"}):
telemetry = Telemetry()
assert telemetry.ready is False
def test_telemetry_disabled_with_crewai_disable_telemetry():
"""Test that telemetry is disabled when CREWAI_DISABLE_TELEMETRY is set to true."""
with patch.dict(os.environ, {"CREWAI_DISABLE_TELEMETRY": "true"}):
telemetry = Telemetry()
assert telemetry.ready is False
@pytest.mark.parametrize("env_var,value,expected_ready", [
("OTEL_SDK_DISABLED", "true", False),
("OTEL_SDK_DISABLED", "TRUE", False),
("CREWAI_DISABLE_TELEMETRY", "true", False),
("CREWAI_DISABLE_TELEMETRY", "TRUE", False),
("OTEL_SDK_DISABLED", "false", True),
("CREWAI_DISABLE_TELEMETRY", "false", True),
])
def test_telemetry_environment_variables(env_var, value, expected_ready):
"""Test telemetry state with different environment variable configurations."""
with patch.dict(os.environ, {env_var: value}):
with patch("crewai.telemetry.telemetry.TracerProvider"):
telemetry = Telemetry()
assert telemetry.ready is expected_ready
def test_telemetry_enabled_by_default():