Enhance tests and refine OpenTelemetry version constraints

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-14 10:32:05 +00:00
parent e60ad726b9
commit 92e2d9491e
2 changed files with 68 additions and 28 deletions

View File

@@ -17,9 +17,9 @@ dependencies = [
"pdfplumber>=0.11.4",
"regex>=2024.9.11",
# Telemetry and Monitoring
"opentelemetry-api>=1.22.0,<2.0.0",
"opentelemetry-sdk>=1.22.0,<2.0.0",
"opentelemetry-exporter-otlp-proto-http>=1.22.0,<2.0.0",
"opentelemetry-api>=1.22.0,<1.32.0",
"opentelemetry-sdk>=1.22.0,<1.32.0",
"opentelemetry-exporter-otlp-proto-http>=1.22.0,<1.32.0",
# Data Handling
"chromadb>=0.5.23",
"openpyxl>=3.1.5",

View File

@@ -4,7 +4,13 @@ import pytest
def test_opentelemetry_imports():
"""Test that all required OpenTelemetry modules can be imported."""
"""Test that all required OpenTelemetry modules can be imported.
This test verifies that all necessary OpenTelemetry modules can be imported
correctly with the current version constraints, ensuring compatibility
between different OpenTelemetry packages.
"""
try:
# Test basic imports
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
@@ -22,9 +28,18 @@ def test_opentelemetry_imports():
assert Span.__module__ == 'opentelemetry.trace.span'
assert Status.__module__ == 'opentelemetry.trace.status'
assert StatusCode.__module__ == 'opentelemetry.trace.status'
except ImportError as e:
pytest.fail(f"Failed to import OpenTelemetry modules: {e}")
def test_telemetry_class_initialization():
"""Test that the Telemetry class can be initialized with current OpenTelemetry versions."""
"""Test that the Telemetry class can be initialized with current OpenTelemetry versions.
This test verifies that the Telemetry class can be properly initialized and
that its core attributes are set correctly. It also tests the set_tracer method
to ensure it works as expected with the current OpenTelemetry versions.
"""
try:
from src.crewai.telemetry.telemetry import Telemetry
# Create an instance of the Telemetry class
@@ -33,6 +48,31 @@ def test_telemetry_class_initialization():
# Check if the telemetry instance is initialized correctly
assert hasattr(telemetry, 'ready')
assert hasattr(telemetry, 'trace_set')
assert telemetry.trace_set is False # Should be False initially
# Try to set the tracer
telemetry.set_tracer()
# After setting the tracer, trace_set should be True if ready is True
if telemetry.ready:
assert telemetry.trace_set is True
except ImportError as e:
pytest.fail(f"Failed to import Telemetry class: {e}")
def test_telemetry_configuration():
"""Test that the Telemetry class can be configured with different options.
This test verifies that the Telemetry class respects environment variables
for disabling telemetry collection.
"""
import os
from src.crewai.telemetry.telemetry import Telemetry
# Test with telemetry disabled via environment variable
os.environ["OTEL_SDK_DISABLED"] = "true"
telemetry = Telemetry()
assert telemetry.ready is False
# Reset environment variable
os.environ.pop("OTEL_SDK_DISABLED", None)