From e9a4d8a4fdff88ace494392d9d40f65510abae57 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 23 Sep 2026 16:54:26 +0200 Subject: [PATCH] chore(openai-agents): Only set gen_ai.provider.name on AI Client spans --- sentry_sdk/integrations/openai_agents/spans/ai_client.py | 2 ++ sentry_sdk/integrations/openai_agents/utils.py | 3 --- tests/integrations/openai_agents/test_openai_agents.py | 8 -------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/sentry_sdk/integrations/openai_agents/spans/ai_client.py b/sentry_sdk/integrations/openai_agents/spans/ai_client.py index 203e4efd74..a145cadd26 100644 --- a/sentry_sdk/integrations/openai_agents/spans/ai_client.py +++ b/sentry_sdk/integrations/openai_agents/spans/ai_client.py @@ -217,6 +217,8 @@ def ai_client_context( }, ) + context.span.set_attribute(SPANDATA.GEN_AI_PROVIDER_NAME, "openai") + _set_agent_data(context.span, agent) if has_data_collection_enabled(client_options): diff --git a/sentry_sdk/integrations/openai_agents/utils.py b/sentry_sdk/integrations/openai_agents/utils.py index b104b2c042..256001786e 100644 --- a/sentry_sdk/integrations/openai_agents/utils.py +++ b/sentry_sdk/integrations/openai_agents/utils.py @@ -47,9 +47,6 @@ def _capture_exception(exc: "Any") -> None: def _set_agent_data(span: "Span", agent: "agents.Agent") -> None: - span.set_attribute( - SPANDATA.GEN_AI_PROVIDER_NAME, "openai" - ) # See footnote for https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-system for explanation why. span.set_attribute(SPANDATA.GEN_AI_AGENT_NAME, agent.name) diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index 227001b3ec..ea8d3a087c 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -472,7 +472,6 @@ async def test_agent_invocation_span_no_pii( assert "gen_ai.response.text" not in invoke_agent_span["attributes"] assert invoke_agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent" - assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent" assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100 assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" @@ -1212,7 +1211,6 @@ async def test_agent_invocation_span( ) assert invoke_agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent" - assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent" assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100 assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" @@ -1329,7 +1327,6 @@ def test_agent_invocation_span_sync_no_pii( assert invoke_agent_span["name"] == "invoke_agent test_agent" assert invoke_agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent" - assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent" assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100 assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" @@ -1589,7 +1586,6 @@ def test_agent_invocation_span_sync( assert invoke_agent_span["name"] == "invoke_agent test_agent" assert invoke_agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent" - assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent" assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100 assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" @@ -1740,7 +1736,6 @@ async def test_tool_execution_span( assert agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" assert agent_span["attributes"]["gen_ai.request.temperature"] == 0.7 assert agent_span["attributes"]["gen_ai.request.top_p"] == 1.0 - assert agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert ai_client_span1["name"] == "chat gpt-4" assert ai_client_span1["attributes"]["gen_ai.operation.name"] == "chat" @@ -1807,7 +1802,6 @@ async def test_tool_execution_span( assert tool_span["attributes"]["gen_ai.request.model"] == "gpt-4" assert tool_span["attributes"]["gen_ai.request.temperature"] == 0.7 assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0 - assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert tool_span["attributes"]["gen_ai.tool.description"] == "A simple tool" assert tool_span["attributes"]["gen_ai.tool.input"] == '{"message": "hello"}' assert tool_span["attributes"]["gen_ai.tool.name"] == "simple_test_tool" @@ -1995,7 +1989,6 @@ async def test_run_streamed_tool_execution_span( assert agent_span["attributes"]["gen_ai.request.model"] == "gpt-4" assert agent_span["attributes"]["gen_ai.request.temperature"] == 0.7 assert agent_span["attributes"]["gen_ai.request.top_p"] == 1.0 - assert agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert tool_span["name"] == "execute_tool simple_test_tool" assert tool_span["attributes"]["gen_ai.agent.name"] == "test_agent" @@ -2005,7 +1998,6 @@ async def test_run_streamed_tool_execution_span( assert tool_span["attributes"]["gen_ai.request.model"] == "gpt-4" assert tool_span["attributes"]["gen_ai.request.temperature"] == 0.7 assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0 - assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai" assert tool_span["attributes"]["gen_ai.tool.description"] == "A simple tool" assert tool_span["attributes"]["gen_ai.tool.input"] == '{"message": "hello"}' assert tool_span["attributes"]["gen_ai.tool.name"] == "simple_test_tool"