|
19 | 19 |
|
20 | 20 | from braintrust.logger import NOOP_SPAN, current_span, init_logger |
21 | 21 |
|
22 | | -from ._wrapper import _create_client_wrapper_class, _create_tool_wrapper_class, _wrap_tool_factory |
| 22 | +from ._wrapper import _create_client_wrapper_class, _create_tool_wrapper_class, _wrap_module_query, _wrap_tool_factory |
23 | 23 |
|
24 | 24 | logger = logging.getLogger(__name__) |
25 | 25 |
|
@@ -69,6 +69,7 @@ def setup_claude_agent_sdk( |
69 | 69 | original_client = claude_agent_sdk.ClaudeSDKClient if hasattr(claude_agent_sdk, "ClaudeSDKClient") else None |
70 | 70 | original_tool_class = claude_agent_sdk.SdkMcpTool if hasattr(claude_agent_sdk, "SdkMcpTool") else None |
71 | 71 | original_tool_fn = claude_agent_sdk.tool if hasattr(claude_agent_sdk, "tool") else None |
| 72 | + original_query_fn = claude_agent_sdk.query if hasattr(claude_agent_sdk, "query") else None |
72 | 73 |
|
73 | 74 | if original_client: |
74 | 75 | wrapped_client = _create_client_wrapper_class(original_client) |
@@ -97,6 +98,15 @@ def setup_claude_agent_sdk( |
97 | 98 | if getattr(module, "tool", None) is original_tool_fn: |
98 | 99 | setattr(module, "tool", wrapped_tool_fn) |
99 | 100 |
|
| 101 | + if original_query_fn: |
| 102 | + wrapped_query_fn = _wrap_module_query(original_query_fn) |
| 103 | + claude_agent_sdk.query = wrapped_query_fn |
| 104 | + |
| 105 | + for module in list(sys.modules.values()): |
| 106 | + if module and hasattr(module, "query"): |
| 107 | + if getattr(module, "query", None) is original_query_fn: |
| 108 | + setattr(module, "query", wrapped_query_fn) |
| 109 | + |
100 | 110 | return True |
101 | 111 | except ImportError: |
102 | 112 | # Not installed - this is expected when using auto_instrument() |
|
0 commit comments