Skip to content

Commit 7f552db

Browse files
committed
httpx: instrument transport instead of client
1 parent 37e05af commit 7f552db

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# pylint: disable=too-many-lines
1616

17+
from __future__ import annotations
18+
1719
import abc
1820
import asyncio
1921
import typing
@@ -593,10 +595,10 @@ def create_transport(
593595
@abc.abstractmethod
594596
def create_client(
595597
self,
596-
transport: typing.Union[
597-
SyncOpenTelemetryTransport, AsyncOpenTelemetryTransport, None
598-
] = None,
599-
**kwargs,
598+
transport: SyncOpenTelemetryTransport
599+
| AsyncOpenTelemetryTransport
600+
| None = None,
601+
**kwargs: typing.Any,
600602
):
601603
pass
602604

@@ -730,9 +732,9 @@ class BaseInstrumentorTest(BaseTest, metaclass=abc.ABCMeta):
730732
@abc.abstractmethod
731733
def create_client(
732734
self,
733-
transport: typing.Union[
734-
SyncOpenTelemetryTransport, AsyncOpenTelemetryTransport, None
735-
] = None,
735+
transport: SyncOpenTelemetryTransport
736+
| AsyncOpenTelemetryTransport
737+
| None = None,
736738
**kwargs,
737739
):
738740
pass
@@ -926,6 +928,17 @@ def test_instrument_client_called_on_the_class(self):
926928
self.assertEqual(result.text, "Hello!")
927929
self.assert_span(num_spans=1)
928930

931+
def test_instrument_multiple_clients_with_the_same_transport(self):
932+
client1 = typing.cast(httpx.Client, self.create_client())
933+
client2 = self.create_client(client1._transport)
934+
935+
HTTPXClientInstrumentor().instrument_client(client1)
936+
HTTPXClientInstrumentor().instrument_client(client2)
937+
938+
result = self.perform_request(self.URL, client=client1)
939+
self.assertEqual(result.text, "Hello!")
940+
self.assert_span(num_spans=1)
941+
929942
def test_instrumentation_without_client(self):
930943
HTTPXClientInstrumentor().instrument()
931944
results = [

0 commit comments

Comments
 (0)