Skip to content

Commit 69cd9f3

Browse files
committed
proper classmethod patching
1 parent 66a2960 commit 69cd9f3

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

sentry_sdk/integrations/openai_agents/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@
1515

1616
def _patch_runner():
1717
# type: () -> None
18-
agents.Runner.run = _create_run_wrapper(agents.Runner.run)
19-
agents.Runner.run_sync = _create_run_wrapper(agents.Runner.run_sync)
20-
agents.Runner.run_streamed = _create_run_wrapper(agents.Runner.run_streamed)
18+
agents.Runner.run = classmethod(
19+
_create_run_wrapper(agents.Runner.run),
20+
)
21+
agents.Runner.run_sync = classmethod(
22+
_create_run_wrapper(agents.Runner.run_sync),
23+
)
24+
agents.Runner.run_streamed = classmethod(
25+
_create_run_wrapper(agents.Runner.run_streamed),
26+
)
2127

2228

2329
def _patch_model():
2430
# type: () -> None
25-
agents.Runner._get_model = _create_get_model_wrapper(agents.Runner._get_model)
31+
agents.Runner._get_model = classmethod(
32+
_create_get_model_wrapper(agents.Runner._get_model),
33+
)
2634

2735

2836
def _patch_tools():
2937
# type: () -> None
30-
agents.Runner._get_all_tools = _create_get_all_tools_wrapper(
31-
agents.Runner._get_all_tools
38+
agents.Runner._get_all_tools = classmethod(
39+
_create_get_all_tools_wrapper(agents.Runner._get_all_tools),
3240
)
3341

3442

sentry_sdk/integrations/openai_agents/patches/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ def _create_get_model_wrapper(original_get_model):
2222
Wraps the agents.Runner._get_model method to wrap the get_response method of the model to create a AI client span.
2323
"""
2424

25-
@classmethod # type: ignore[misc]
26-
@wraps(original_get_model)
25+
@wraps(
26+
original_get_model.__func__
27+
if hasattr(original_get_model, "__func__")
28+
else original_get_model
29+
)
2730
def wrapped_get_model(cls, agent, run_config):
2831
# type: (agents.Runner, agents.Agent, agents.RunConfig) -> agents.Model
2932

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def _create_run_wrapper(original_func):
2525
"""
2626
is_async = asyncio.iscoroutinefunction(original_func)
2727

28-
@classmethod # type: ignore[misc]
29-
@wraps(original_func)
28+
@wraps(
29+
original_func.__func__ if hasattr(original_func, "__func__") else original_func
30+
)
3031
async def async_wrapper(cls, *args, **kwargs):
3132
# type: (agents.Runner, *Any, **Any) -> Any
3233
agent = args[0]
@@ -37,8 +38,9 @@ async def async_wrapper(cls, *args, **kwargs):
3738

3839
return result
3940

40-
@classmethod # type: ignore[misc]
41-
@wraps(original_func)
41+
@wraps(
42+
original_func.__func__ if hasattr(original_func, "__func__") else original_func
43+
)
4244
def sync_wrapper(cls, *args, **kwargs):
4345
# type: (agents.Runner, *Any, **Any) -> Any
4446
agent = args[0]

sentry_sdk/integrations/openai_agents/patches/tools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ def _create_get_all_tools_wrapper(original_get_all_tools):
2121
Wraps the agents.Runner._get_all_tools method of the Runner class to wrap all function tools with Sentry instrumentation.
2222
"""
2323

24-
@classmethod # type: ignore[misc]
25-
@wraps(original_get_all_tools)
24+
@wraps(
25+
original_get_all_tools.__func__
26+
if hasattr(original_get_all_tools, "__func__")
27+
else original_get_all_tools
28+
)
2629
async def wrapped_get_all_tools(cls, agent, context_wrapper):
2730
# type: (agents.Runner, agents.Agent, agents.RunContextWrapper) -> list[agents.Tool]
2831

0 commit comments

Comments
 (0)