mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 08:38:30 +00:00
Add span creation test and documentation for version constraints
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user