Skip to content

Commit 47c2ac3

Browse files
authored
feat(openai-agents): add support for exclusive processor configuration (#1586)
1 parent cb0f60b commit 47c2ac3

File tree

1 file changed

+10
-2
lines changed
  • python/instrumentation/openinference-instrumentation-openai-agents/src/openinference/instrumentation/openai_agents

1 file changed

+10
-2
lines changed

python/instrumentation/openinference-instrumentation-openai-agents/src/openinference/instrumentation/openai_agents/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def instrumentation_dependencies(self) -> Collection[str]:
2424
def _instrument(self, **kwargs: Any) -> None:
2525
if not (tracer_provider := kwargs.get("tracer_provider")):
2626
tracer_provider = trace_api.get_tracer_provider()
27+
if not (exclusive_processor := kwargs.get("exclusive_processor")):
28+
exclusive_processor = False
2729
if not (config := kwargs.get("config")):
2830
config = TraceConfig()
2931
else:
@@ -32,13 +34,19 @@ def _instrument(self, **kwargs: Any) -> None:
3234
trace_api.get_tracer(__name__, __version__, tracer_provider),
3335
config=config,
3436
)
35-
from agents import add_trace_processor
3637

3738
from openinference.instrumentation.openai_agents._processor import (
3839
OpenInferenceTracingProcessor,
3940
)
4041

41-
add_trace_processor(OpenInferenceTracingProcessor(cast(Tracer, tracer)))
42+
if exclusive_processor:
43+
from agents import set_trace_processors
44+
45+
set_trace_processors([OpenInferenceTracingProcessor(cast(Tracer, tracer))])
46+
else:
47+
from agents import add_trace_processor
48+
49+
add_trace_processor(OpenInferenceTracingProcessor(cast(Tracer, tracer)))
4250

4351
def _uninstrument(self, **kwargs: Any) -> None:
4452
# TODO

0 commit comments

Comments
 (0)