Skip to content

Commit 7f3c706

Browse files
committed
lint
1 parent 17eda0f commit 7f3c706

7 files changed

Lines changed: 34 additions & 30 deletions

File tree

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
Rewrite on top of `opentelemetry-util-genai`. The instrumentor now registers a single `TracingProcessor` with the agents library (`agents.tracing.add_trace_processor`) and turns its `Trace` / `AgentSpan` / `FunctionSpan` callbacks into `invoke_workflow` / `invoke_agent` / `execute_tool` spans. The workflow span carries a `gen_ai.workflow.name` attribute sourced from the agents library's `RunConfig.workflow_name`. LLM-level spans are not emitted by this package — install `opentelemetry-instrumentation-genai-openai` alongside to capture them. Removes the `OTEL_INSTRUMENTATION_OPENAI_AGENTS_*` environment variables and the matching instrumentor kwargs. New `disable_openai_trace_export=True` instrumentor kwarg replaces the default OpenAI-hosted trace exporter so traces flow only via OTel. Handoff / guardrail / speech / transcription spans are no longer emitted pending semconv. `execute_tool` spans are missing `gen_ai.tool.call.id` because the agents library's `FunctionSpanData` does not expose it — tracked in [#86](https://github.com/open-telemetry/opentelemetry-python-genai/issues/86).
1+
Rewrite on top of `opentelemetry-util-genai`:
2+
3+
- Emits `invoke_workflow`, `invoke_agent`, `execute_tool` spans via a `TracingProcessor`
4+
registered with `agents.tracing.add_trace_processor`.
5+
- Workflow span carries `gen_ai.workflow.name` from `RunConfig.workflow_name`.
6+
- LLM spans (`chat` / `responses` / `embeddings`) now come from
7+
`opentelemetry-instrumentation-genai-openai` when installed; this package no longer
8+
emits them.
9+
- Handoff / guardrail / speech / transcription spans are no longer emitted, pending semconv.
10+
- New `disable_openai_trace_export=True` instrumentor kwarg removes the default
11+
OpenAI-hosted trace exporter.
12+
- Removes the `OTEL_INSTRUMENTATION_OPENAI_AGENTS_*` env vars and matching instrumentor kwargs.
13+
14+
Known gap: `execute_tool` spans are missing `gen_ai.tool.call.id` because the agents library's `FunctionSpanData` does not expose it ([#86](https://github.com/open-telemetry/opentelemetry-python-genai/issues/86)).

instrumentation/opentelemetry-instrumentation-genai-openai-agents/examples/manual/main.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@
3232
from opentelemetry.sdk.trace.export import BatchSpanProcessor
3333

3434

35-
def configure_otel() -> (
36-
tuple[TracerProvider, MeterProvider, LoggerProvider]
37-
):
35+
def configure_otel() -> tuple[TracerProvider, MeterProvider, LoggerProvider]:
3836
"""Configure OpenTelemetry providers and install the instrumentor."""
3937

4038
tracer_provider = TracerProvider()
41-
tracer_provider.add_span_processor(
42-
BatchSpanProcessor(OTLPSpanExporter())
43-
)
39+
tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
4440
trace.set_tracer_provider(tracer_provider)
4541

4642
meter_provider = MeterProvider(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class GenAITracingProcessor(TracingProcessor):
7070
def __init__(self, handler: TelemetryHandler, provider: str) -> None:
7171
self._handler = handler
7272
self._provider = provider
73-
self._invocations: weakref.WeakKeyDictionary[
74-
Any, GenAIInvocation
75-
] = weakref.WeakKeyDictionary()
73+
self._invocations: weakref.WeakKeyDictionary[Any, GenAIInvocation] = (
74+
weakref.WeakKeyDictionary()
75+
)
7676

7777
def on_trace_start(self, trace: Trace) -> None:
7878
# ``trace.name`` comes from ``RunConfig.workflow_name`` (default

instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/conformance/orchestration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ class OrchestrationScenario(Scenario):
7474
"invoke_agent",
7575
"execute_tool",
7676
)
77-
expected_metrics = (
78-
"gen_ai.client.operation.duration",
79-
)
77+
expected_metrics = ("gen_ai.client.operation.duration",)
8078
expected_violations = (
8179
# `FunctionSpanData` in the openai-agents library doesn't expose
8280
# `tool_call_id`, so our `execute_tool` spans can't set

instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_instrumentor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def test_instrument_adds_processor_alongside_default() -> None:
4949
assert len(_our_processors()) == 0
5050

5151

52-
def test_instrument_with_disable_openai_trace_export_replaces_processors() -> None:
52+
def test_instrument_with_disable_openai_trace_export_replaces_processors() -> (
53+
None
54+
):
5355
# Make sure the default processor is registered before we start,
5456
# so the "replace" behavior is observable.
5557
agents.tracing.set_trace_processors(

instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_processor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from __future__ import annotations
55

6-
from types import SimpleNamespace
6+
import gc
77
from typing import Any
88
from unittest.mock import MagicMock
99

@@ -76,7 +76,9 @@ def test_agent_span_creates_invoke_local_agent() -> None:
7676
handler.invoke_local_agent.return_value.stop.assert_called_once_with()
7777

7878

79-
def test_function_span_creates_tool_invocation_and_sets_provider_metric() -> None:
79+
def test_function_span_creates_tool_invocation_and_sets_provider_metric() -> (
80+
None
81+
):
8082
handler = _build_handler()
8183
handler.tool.return_value = MagicMock(
8284
spec=ToolInvocation, metric_attributes={}
@@ -98,8 +100,7 @@ def test_function_span_creates_tool_invocation_and_sets_provider_metric() -> Non
98100
)
99101
tool_invocation = handler.tool.return_value
100102
assert (
101-
tool_invocation.metric_attributes["gen_ai.provider.name"]
102-
== "openai"
103+
tool_invocation.metric_attributes["gen_ai.provider.name"] == "openai"
103104
)
104105

105106
# Output gets populated on the agents library span_data after the
@@ -182,8 +183,6 @@ def test_shutdown_stops_open_invocations() -> None:
182183

183184

184185
def test_state_uses_weakref_so_dropped_spans_are_collected() -> None:
185-
import gc
186-
187186
handler = _build_handler()
188187
processor = GenAITracingProcessor(handler, provider="openai")
189188
span: _Span | None = _Span(AgentSpanData(name="triage"))

util/opentelemetry-test-util-genai/src/opentelemetry/test_util_genai/conformance.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ class ExpectedViolation:
8484
message_substring: str
8585

8686
def matches(self, violation: dict[str, Any]) -> bool:
87-
return (
88-
violation.get("id") == self.advice_id
89-
and self.message_substring
90-
in str(violation.get("message", ""))
87+
return violation.get(
88+
"id"
89+
) == self.advice_id and self.message_substring in str(
90+
violation.get("message", "")
9191
)
9292

9393

@@ -236,17 +236,13 @@ def run_conformance(
236236
logger_provider.shutdown()
237237

238238

239-
def _check_violations(
240-
scenario: Scenario, report: LiveCheckReport
241-
) -> None:
239+
def _check_violations(scenario: Scenario, report: LiveCheckReport) -> None:
242240
"""Reconcile weaver violations against ``scenario.expected_violations``."""
243241
violations = report.violations
244242
expected = scenario.expected_violations
245243

246244
unexpected = [
247-
v
248-
for v in violations
249-
if not any(ev.matches(v) for ev in expected)
245+
v for v in violations if not any(ev.matches(v) for ev in expected)
250246
]
251247
if unexpected:
252248
raise LiveCheckError(

0 commit comments

Comments
 (0)