fix: stop anonymous telemetry from globalizing the TracerProvider

`Telemetry.set_tracer()` installed crewAI's anonymous SDK
`TracerProvider` into OpenTelemetry's process-global slot, so the first
`Crew` constructed in a test or host application replaced the default
`ProxyTracerProvider` and exfiltrated every host span emitted via
`trace.get_tracer(...)` to crewAI's OTLP endpoint. Keep the provider
local to the `Telemetry` instance and route every anonymous span
through `self.provider.get_tracer("crewai.telemetry")` so the global
slot stays untouched. Mirrors the fix in `crewai_core.telemetry`,
drops the now-dead `set_tracer()` calls in `event_listener.py` and
`crewai_cli.command`, and adds regression coverage that asserts the
provider stays a `ProxyTracerProvider` after constructing a `Crew`.
This commit is contained in:
Lucas Gomide
2026-06-23 13:46:55 -03:00
committed by lorenzejay
parent fd4ef602d0
commit 0329972e1a

View File

@@ -51,6 +51,21 @@ def test_operation_yields_non_recording_span_when_no_provider() -> None:
assert isinstance(span, NonRecordingSpan)
def test_constructing_crew_does_not_globalize_anonymous_telemetry_provider() -> None:
agent = Agent(
role="tester",
goal="goal",
backstory="backstory",
llm=_FakeLLM(),
allow_delegation=False,
)
Crew(
agents=[agent],
tasks=[Task(description="d", expected_output="o", agent=agent)],
)
assert isinstance(trace.get_tracer_provider(), ProxyTracerProvider)
def test_kickoff_runs_cleanly_without_provider() -> None:
agent = Agent(
role="tester",