Skip to content

Commit bdacfd1

Browse files
chore(openai-agents): Stop setting gen_ai.request.model on Invoke Agent spans
1 parent ad13d87 commit bdacfd1

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

‎sentry_sdk/integrations/openai_agents/spans/ai_client.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
HostedMCPTool,
1616
ImageGenerationTool,
1717
LocalShellTool,
18+
Model,
1819
WebSearchTool,
1920
)
2021
except ImportError:
@@ -216,6 +217,17 @@ def ai_client_context(
216217
},
217218
)
218219

220+
model_name: "Optional[str]" = None
221+
if isinstance(agent.model, Model) and hasattr(agent.model, "model"):
222+
model_name = agent.model.model
223+
elif isinstance(agent.model, str):
224+
model_name = agent.model
225+
elif hasattr(agent, "_sentry_request_model"):
226+
model_name = agent._sentry_request_model
227+
228+
if model_name:
229+
context.span.set_attribute(SPANDATA.GEN_AI_REQUEST_MODEL, model_name)
230+
219231
_set_agent_data(context.span, agent)
220232

221233
if client_options["data_collection"]["gen_ai"]["inputs"]:

‎sentry_sdk/integrations/openai_agents/utils.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
)
2323

2424
if TYPE_CHECKING:
25-
from typing import Any, Optional
25+
from typing import Any
2626

2727
from agents import TResponseInputItem, Usage
2828

2929
from sentry_sdk._types import TextPart
3030

3131
try:
3232
import agents
33-
from agents import Model
3433
except ImportError:
3534
raise DidNotEnable("OpenAI Agents not installed")
3635

@@ -56,17 +55,6 @@ def _set_agent_data(span: "Span", agent: "agents.Agent") -> None:
5655
SPANDATA.GEN_AI_REQUEST_MAX_TOKENS, agent.model_settings.max_tokens
5756
)
5857

59-
model_name: "Optional[str]" = None
60-
if isinstance(agent.model, Model) and hasattr(agent.model, "model"):
61-
model_name = agent.model.model
62-
elif isinstance(agent.model, str):
63-
model_name = agent.model
64-
elif hasattr(agent, "_sentry_request_model"):
65-
model_name = agent._sentry_request_model
66-
67-
if model_name:
68-
span.set_attribute(SPANDATA.GEN_AI_REQUEST_MODEL, model_name)
69-
7058
if agent.model_settings.presence_penalty:
7159
span.set_attribute(
7260
SPANDATA.GEN_AI_REQUEST_PRESENCE_PENALTY,

‎tests/integrations/openai_agents/test_openai_agents.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ async def test_agent_invocation_span_no_sensitive_data(
484484
assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
485485
assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent"
486486
assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
487-
assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
488487
assert invoke_agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
489488
assert invoke_agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
490489

@@ -765,7 +764,6 @@ async def test_agent_invocation_span(
765764
assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
766765
assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent"
767766
assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
768-
assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
769767
assert invoke_agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
770768
assert invoke_agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
771769

@@ -888,7 +886,6 @@ def test_agent_invocation_span_sync_no_sensitive_data(
888886
assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
889887
assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent"
890888
assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
891-
assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
892889
assert invoke_agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
893890
assert invoke_agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
894891

@@ -1153,7 +1150,6 @@ def test_agent_invocation_span_sync(
11531150
assert invoke_agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
11541151
assert invoke_agent_span["attributes"]["gen_ai.agent.name"] == "test_agent"
11551152
assert invoke_agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
1156-
assert invoke_agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
11571153
assert invoke_agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
11581154
assert invoke_agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
11591155

@@ -1303,7 +1299,6 @@ async def test_tool_execution_span(
13031299
assert agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent"
13041300

13051301
assert agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
1306-
assert agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
13071302
assert agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
13081303
assert agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
13091304
assert agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
@@ -1370,7 +1365,6 @@ async def test_tool_execution_span(
13701365
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
13711366

13721367
assert tool_span["attributes"]["gen_ai.request.max_tokens"] == 100
1373-
assert tool_span["attributes"]["gen_ai.request.model"] == "gpt-4"
13741368
assert tool_span["attributes"]["gen_ai.request.temperature"] == 0.7
13751369
assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0
13761370
assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
@@ -1563,7 +1557,6 @@ async def test_run_streamed_tool_execution_span(
15631557
assert agent_span["attributes"]["gen_ai.operation.name"] == "invoke_agent"
15641558

15651559
assert agent_span["attributes"]["gen_ai.request.max_tokens"] == 100
1566-
assert agent_span["attributes"]["gen_ai.request.model"] == "gpt-4"
15671560
assert agent_span["attributes"]["gen_ai.request.temperature"] == 0.7
15681561
assert agent_span["attributes"]["gen_ai.request.top_p"] == 1.0
15691562
assert agent_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
@@ -1573,7 +1566,6 @@ async def test_run_streamed_tool_execution_span(
15731566
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
15741567

15751568
assert tool_span["attributes"]["gen_ai.request.max_tokens"] == 100
1576-
assert tool_span["attributes"]["gen_ai.request.model"] == "gpt-4"
15771569
assert tool_span["attributes"]["gen_ai.request.temperature"] == 0.7
15781570
assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0
15791571
assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"

0 commit comments

Comments
 (0)