Compare commits

...

5 Commits

Author SHA1 Message Date
Devin AI
9eab90a0fd Merge remote-tracking branch 'origin/main' into devin/1744096499-fix-telemetry-disable 2025-04-09 17:13:59 +00:00
Devin AI
741f3118a9 Revert telemetry implementation changes while keeping CREWAI_DISABLE_TELEMETRY functionality
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-09 17:07:58 +00:00
Devin AI
c9cfe0a208 Fix telemetry implementation based on PR feedback
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-08 07:22:14 +00:00
Devin AI
04304f236c Fix import order in telemetry test file
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-08 07:17:48 +00:00
Devin AI
d656c2d224 Fix #2536: Add CREWAI_DISABLE_TELEMETRY environment variable
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-08 07:16:01 +00:00
4 changed files with 51 additions and 5 deletions

View File

@@ -22,7 +22,16 @@ usage of tools, API calls, responses, any data processed by the agents, or secre
When the `share_crew` feature is enabled, detailed data including task descriptions, agents' backstories or goals, and other specific attributes are collected
to provide deeper insights. This expanded data collection may include personal information if users have incorporated it into their crews or tasks.
Users should carefully consider the content of their crews and tasks before enabling `share_crew`.
Users can disable telemetry by setting the environment variable `OTEL_SDK_DISABLED` to `true`.
Users can disable telemetry by setting the environment variable `CREWAI_DISABLE_TELEMETRY` to `true` or by setting `OTEL_SDK_DISABLED` to `true` (note that the latter disables all OpenTelemetry instrumentation globally).
### Examples:
```python
# Disable CrewAI telemetry only
os.environ['CREWAI_DISABLE_TELEMETRY'] = 'true'
# Disable all OpenTelemetry (including CrewAI)
os.environ['OTEL_SDK_DISABLED'] = 'true'
```
### Data Explanation:
| Defaulted | Data | Reason and Specifics |
@@ -55,4 +64,4 @@ This enables a deeper insight into usage patterns.
<Warning>
If you enable `share_crew`, the collected data may include personal information if it has been incorporated into crew configurations, task descriptions, or outputs.
Users should carefully review their data and ensure compliance with GDPR and other applicable privacy regulations before enabling this feature.
</Warning>
</Warning>

View File

@@ -45,10 +45,10 @@ class Telemetry:
"""
def __init__(self):
self.ready = False
self.trace_set = False
self.ready: bool = False
self.trace_set: bool = False
if os.getenv("OTEL_SDK_DISABLED", "false").lower() == "true":
if self._is_telemetry_disabled():
return
try:
@@ -75,6 +75,13 @@ class Telemetry:
):
raise # Re-raise the exception to not interfere with system signals
self.ready = False
def _is_telemetry_disabled(self) -> bool:
"""Check if telemetry should be disabled based on environment variables."""
return (
os.getenv("OTEL_SDK_DISABLED", "false").lower() == "true" or
os.getenv("CREWAI_DISABLE_TELEMETRY", "false").lower() == "true"
)
def set_tracer(self):
if self.ready and not self.trace_set:

View File

View File

@@ -0,0 +1,30 @@
import os
from unittest.mock import patch
import pytest
from crewai.telemetry import Telemetry
@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():
"""Test that telemetry is enabled by default."""
with patch.dict(os.environ, {}, clear=True):
with patch("crewai.telemetry.telemetry.TracerProvider"):
telemetry = Telemetry()
assert telemetry.ready is True