mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Fix telemetry singleton pattern to respect dynamic environment variables (#2946)
* Fix telemetry singleton pattern to respect dynamic environment variables - Modified Telemetry.__init__ to prevent re-initialization with _initialized flag - Updated _safe_telemetry_operation to check _is_telemetry_disabled() dynamically - Added comprehensive tests for environment variables set after singleton creation - Fixed singleton contamination in existing tests by adding proper reset - Resolves issue #2945 where CREWAI_DISABLE_TELEMETRY=true was ignored when set after import Co-Authored-By: João <joao@crewai.com> * Implement code review improvements - Move _initialized flag to __new__ method for better encapsulation - Add type hints to _safe_telemetry_operation method - Consolidate telemetry execution checks into _should_execute_telemetry helper - Add pytest fixtures to reduce test setup redundancy - Enhanced documentation for singleton behavior Co-Authored-By: João <joao@crewai.com> * Fix mypy type-checker errors - Add explicit bool type annotation to _initialized field - Fix return value in task_started method to not return _safe_telemetry_operation result - Simplify initialization logic to set _initialized once in __init__ Co-Authored-By: João <joao@crewai.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: João <joao@crewai.com> Co-authored-by: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
739eb72fd0
commit
06c991d8c3
@@ -9,6 +9,14 @@ from crewai.telemetry import Telemetry
|
||||
from opentelemetry import trace
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup_telemetry():
|
||||
"""Automatically clean up Telemetry singleton between tests."""
|
||||
Telemetry._instance = None
|
||||
yield
|
||||
Telemetry._instance = None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"env_var,value,expected_ready",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user