Skip to content

Commit 7660a00

Browse files
committed
Do nothing on transport already instrumented
1 parent b89ee8f commit 7660a00

File tree

1 file changed

+9
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx

1 file changed

+9
-3
lines changed

instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,15 @@ def instrument_client(
890890
that is called right before the span ends
891891
"""
892892

893-
if getattr(
894-
client._transport, "_is_instrumented_by_opentelemetry", False
895-
):
893+
if getattr(client, "_is_instrumented_by_opentelemetry", False):
896894
_logger.warning(
897895
"Attempting to instrument Httpx client while already instrumented"
898896
)
899897
return
898+
if getattr(
899+
client._transport, "is_instrumented_by_opentelemetry", False
900+
):
901+
return
900902

901903
_OpenTelemetrySemanticConventionStability._initialize()
902904
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
@@ -949,6 +951,7 @@ def instrument_client(
949951
),
950952
)
951953
client._transport._is_instrumented_by_opentelemetry = True
954+
client._is_instrumented_by_opentelemetry = True
952955
if hasattr(client._transport, "handle_async_request"):
953956
wrap_function_wrapper(
954957
client._transport,
@@ -975,6 +978,7 @@ def instrument_client(
975978
),
976979
)
977980
client._transport._is_instrumented_by_opentelemetry = True
981+
client._is_instrumented_by_opentelemetry = True
978982

979983
@staticmethod
980984
def uninstrument_client(
@@ -990,8 +994,10 @@ def uninstrument_client(
990994
for transport in client._mounts.values():
991995
unwrap(transport, "handle_request")
992996
client._transport._is_instrumented_by_opentelemetry = False
997+
client._is_instrumented_by_opentelemetry = False
993998
elif hasattr(client._transport, "handle_async_request"):
994999
unwrap(client._transport, "handle_async_request")
9951000
for transport in client._mounts.values():
9961001
unwrap(transport, "handle_async_request")
9971002
client._transport._is_instrumented_by_opentelemetry = False
1003+
client._is_instrumented_by_opentelemetry = False

0 commit comments

Comments
 (0)