Skip to content

Commit 1b7bb0f

Browse files
committed
Add tests for subclassed clients
1 parent bc68edc commit 1b7bb0f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

11871202
class 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

Comments
 (0)