Add span creation test and documentation for version constraints

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-14 10:37:49 +00:00
parent 2d07504b96
commit ae88b56f9c
2 changed files with 36 additions and 0 deletions

View File

@@ -17,6 +17,8 @@ dependencies = [
"pdfplumber>=0.11.4",
"regex>=2024.9.11",
# Telemetry and Monitoring
# Version constraints ensure compatibility with various OpenTelemetry versions
# while preventing installation of incompatible versions (issue #2372)
"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",

View File

@@ -79,3 +79,37 @@ def test_telemetry_configuration():
# Reset environment variable
os.environ.pop("OTEL_SDK_DISABLED", None)
def test_span_creation():
"""Test that spans can be created with the current OpenTelemetry versions.
This test verifies that the Telemetry class can create spans using the
OpenTelemetry tracer, which is a core functionality for telemetry.
"""
import os
from opentelemetry import trace
from src.crewai.telemetry.telemetry import Telemetry
# Ensure telemetry is enabled for this test
if "OTEL_SDK_DISABLED" in os.environ:
old_value = os.environ.pop("OTEL_SDK_DISABLED")
try:
telemetry = Telemetry()
telemetry.set_tracer()
# Only test span creation if telemetry is ready
if telemetry.ready and telemetry.trace_set:
tracer = trace.get_tracer("crewai.telemetry.test")
if tracer:
with tracer.start_as_current_span("test_operation") as span:
assert span is not None
assert span.is_recording()
except Exception as e:
pytest.fail(f"Failed to create span: {e}")
finally:
# Restore environment variable if it was set
if "old_value" in locals():
os.environ["OTEL_SDK_DISABLED"] = old_value