Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from unittest.mock import MagicMock, patch
import os
import json
import logging

import sentry_sdk
from sentry_sdk import start_span
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.openai_agents.utils import _set_input_data, safe_serialize
from sentry_sdk.utils import parse_version

Expand Down Expand Up @@ -1118,6 +1120,11 @@ def simple_test_tool(message: str) -> str:
available_tools[0].update(
{"tool_input_guardrails": None, "tool_output_guardrails": None}
)
if parse_version(OPENAI_AGENTS_VERSION) >= (
0,
8,
):
available_tools[0]["needs_approval"] = False

available_tools = safe_serialize(available_tools)

Expand Down Expand Up @@ -1484,7 +1491,11 @@ async def test_error_handling(sentry_init, capture_events, test_agent):
mock_get_response.side_effect = Exception("Model Error")

sentry_init(
integrations=[OpenAIAgentsIntegration()],
disabled_integrations=[],
integrations=[
OpenAIAgentsIntegration(),
LoggingIntegration(event_level=logging.CRITICAL),
],
traces_sample_rate=1.0,
)

Expand Down Expand Up @@ -1532,7 +1543,10 @@ async def test_error_captures_input_data(sentry_init, capture_events, test_agent
mock_get_response.side_effect = Exception("API Error")

sentry_init(
integrations=[OpenAIAgentsIntegration()],
integrations=[
OpenAIAgentsIntegration(),
LoggingIntegration(event_level=logging.CRITICAL),
],
traces_sample_rate=1.0,
send_default_pii=True,
)
Expand Down Expand Up @@ -1577,7 +1591,10 @@ async def test_span_status_error(sentry_init, capture_events, test_agent):
mock_get_response.side_effect = ValueError("Model Error")

sentry_init(
integrations=[OpenAIAgentsIntegration()],
integrations=[
OpenAIAgentsIntegration(),
LoggingIntegration(event_level=logging.CRITICAL),
],
traces_sample_rate=1.0,
)

Expand Down Expand Up @@ -2692,27 +2709,6 @@ def test_openai_agents_message_truncation(sentry_init, capture_events):
assert "small message 5" in str(parsed_messages[0])


def test_streaming_patches_applied(sentry_init):
"""
Test that the streaming patches are applied correctly.
"""
sentry_init(
integrations=[OpenAIAgentsIntegration()],
traces_sample_rate=1.0,
)

# Verify that run_streamed is patched (will have __wrapped__ attribute if patched)
import agents

# Check that the method exists and has been modified
assert hasattr(agents.run.DEFAULT_AGENT_RUNNER, "run_streamed")
assert hasattr(agents.run.AgentRunner, "_run_single_turn_streamed")

# Verify the patches were applied by checking for our wrapper
run_streamed_func = agents.run.DEFAULT_AGENT_RUNNER.run_streamed
assert run_streamed_func is not None


@pytest.mark.asyncio
async def test_streaming_span_update_captures_response_data(
sentry_init, test_agent, mock_usage
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ envlist =

# ~~~ Agents ~~~
{py3.10,py3.11,py3.12}-openai_agents-v0.0.19
{py3.10,py3.12,py3.13}-openai_agents-v0.2.11
{py3.10,py3.12,py3.13}-openai_agents-v0.4.2
{py3.10,py3.13,py3.14,py3.14t}-openai_agents-v0.7.0
{py3.10,py3.12,py3.13}-openai_agents-v0.3.3
{py3.10,py3.13,py3.14,py3.14t}-openai_agents-v0.6.9
{py3.10,py3.13,py3.14,py3.14t}-openai_agents-v0.8.1

{py3.10,py3.12,py3.13}-pydantic_ai-v1.0.18
{py3.10,py3.12,py3.13}-pydantic_ai-v1.18.0
Expand Down Expand Up @@ -398,9 +398,9 @@ deps =

# ~~~ Agents ~~~
openai_agents-v0.0.19: openai-agents==0.0.19
openai_agents-v0.2.11: openai-agents==0.2.11
openai_agents-v0.4.2: openai-agents==0.4.2
openai_agents-v0.7.0: openai-agents==0.7.0
openai_agents-v0.3.3: openai-agents==0.3.3
openai_agents-v0.6.9: openai-agents==0.6.9
openai_agents-v0.8.1: openai-agents==0.8.1
openai_agents: pytest-asyncio

pydantic_ai-v1.0.18: pydantic-ai==1.0.18
Expand Down
Loading