1616
1717from __future__ import annotations
1818
19- import importlib
2019import os
21- from typing import TYPE_CHECKING , Any , Collection , Protocol
20+ from typing import Collection , Protocol
21+
22+ from agents import tracing
23+ from agents .tracing .processor_interface import TracingProcessor
2224
2325from opentelemetry .instrumentation .instrumentor import BaseInstrumentor
2426from opentelemetry .semconv ._incubating .attributes import (
3133from .span_processor import _OpenAIAgentsSpanProcessor
3234from .version import __version__ # noqa: F401
3335
34- if TYPE_CHECKING :
35- from agents .tracing .processor_interface import TracingProcessor
36- else : # pragma: no cover - runtime fallback when Agents SDK isn't installed
37- TracingProcessor = Any
38-
3936
4037class _ProcessorHolder (Protocol ):
4138 _processors : Collection [TracingProcessor ]
@@ -48,10 +45,6 @@ class _TraceProviderLike(Protocol):
4845__all__ = ["OpenAIAgentsInstrumentor" ]
4946
5047
51- def _load_tracing_module ():
52- return importlib .import_module ("agents.tracing" )
53-
54-
5548def _resolve_system (value : str | None ) -> str :
5649 if not value :
5750 return GenAI .GenAiSystemValues .OPENAI .value
@@ -108,7 +101,6 @@ def _instrument(self, **kwargs) -> None:
108101 agent_name_override = agent_name_override ,
109102 )
110103
111- tracing = _load_tracing_module ()
112104 provider = tracing .get_trace_provider ()
113105 existing = _get_registered_processors (provider )
114106 provider .set_processors ([* existing , processor ])
@@ -118,7 +110,6 @@ def _uninstrument(self, **kwargs) -> None:
118110 if self ._processor is None :
119111 return
120112
121- tracing = _load_tracing_module ()
122113 provider = tracing .get_trace_provider ()
123114 current = _get_registered_processors (provider )
124115 filtered = [proc for proc in current if proc is not self ._processor ]
0 commit comments