Skip to content

Commit 20e80a3

Browse files
committed
Annotate OpenAI trace provider helper
1 parent ba45d16 commit 20e80a3

File tree

1 file changed

+23
-2
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-openai-agents/src/opentelemetry/instrumentation/openai_agents

1 file changed

+23
-2
lines changed

instrumentation-genai/opentelemetry-instrumentation-openai-agents/src/opentelemetry/instrumentation/openai_agents/__init__.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import importlib
2020
import os
21-
from typing import Collection
21+
from typing import TYPE_CHECKING, Any, Collection, Protocol
2222

2323
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
2424
from opentelemetry.semconv._incubating.attributes import (
@@ -31,6 +31,20 @@
3131
from .span_processor import _OpenAIAgentsSpanProcessor
3232
from .version import __version__ # noqa: F401
3333

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+
39+
40+
class _ProcessorHolder(Protocol):
41+
_processors: Collection[TracingProcessor]
42+
43+
44+
class _TraceProviderLike(Protocol):
45+
_multi_processor: _ProcessorHolder
46+
47+
3448
__all__ = ["OpenAIAgentsInstrumentor"]
3549

3650

@@ -51,7 +65,14 @@ def _resolve_system(value: str | None) -> str:
5165
return value
5266

5367

54-
def _get_registered_processors(provider) -> list:
68+
def _get_registered_processors(
69+
provider: _TraceProviderLike,
70+
) -> list[TracingProcessor]:
71+
"""Return tracing processors registered on the OpenAI Agents trace provider.
72+
73+
The provider exposes a private `_multi_processor` attribute with a `_processors`
74+
collection that stores the currently registered processors in execution order.
75+
"""
5576
multi = getattr(provider, "_multi_processor", None)
5677
processors = getattr(multi, "_processors", ())
5778
return list(processors)

0 commit comments

Comments
 (0)