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