From ae88b56f9c698b68409f9ee6cb34aed629e9d493 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 14 Mar 2025 10:37:49 +0000 Subject: [PATCH] Add span creation test and documentation for version constraints Co-Authored-By: Joe Moura --- pyproject.toml | 2 ++ .../test_opentelemetry_compatibility.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 123744369..36286b555 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/telemetry/test_opentelemetry_compatibility.py b/tests/telemetry/test_opentelemetry_compatibility.py index cfe5c58a5..e36d33b9d 100644 --- a/tests/telemetry/test_opentelemetry_compatibility.py +++ b/tests/telemetry/test_opentelemetry_compatibility.py @@ -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