@@ -1182,6 +1182,21 @@ def perform_request(
11821182 def create_proxy_transport (self , url ):
11831183 return httpx .HTTPTransport (proxy = httpx .Proxy (url ))
11841184
1185+ def test_can_instrument_subclassed_client (self ):
1186+ class CustomClient (httpx .Client ):
1187+ pass
1188+
1189+ client = CustomClient ()
1190+ self .assertFalse (
1191+ isinstance (client ._transport .handle_request , ObjectProxy )
1192+ )
1193+
1194+ HTTPXClientInstrumentor ().instrument ()
1195+
1196+ self .assertTrue (
1197+ isinstance (client ._transport .handle_request , ObjectProxy )
1198+ )
1199+
11851200
11861201class TestAsyncInstrumentationIntegration (BaseTestCases .BaseInstrumentorTest ):
11871202 response_hook = staticmethod (_async_response_hook )
@@ -1257,3 +1272,18 @@ def test_async_request_hook_does_nothing_if_not_coroutine(self):
12571272 self .assertEqual (result .text , "Hello!" )
12581273 span = self .assert_span ()
12591274 self .assertEqual (span .name , "GET" )
1275+
1276+ def test_can_instrument_subclassed_async_client (self ):
1277+ class CustomAsyncClient (httpx .AsyncClient ):
1278+ pass
1279+
1280+ client = CustomAsyncClient ()
1281+ self .assertFalse (
1282+ isinstance (client ._transport .handle_async_request , ObjectProxy )
1283+ )
1284+
1285+ HTTPXClientInstrumentor ().instrument ()
1286+
1287+ self .assertTrue (
1288+ isinstance (client ._transport .handle_async_request , ObjectProxy )
1289+ )
0 commit comments