Skip to content
Draft
Prev Previous commit
Next Next commit
Fix test
  • Loading branch information
Kludex committed Dec 13, 2024
commit ed97732e6dec8b75ec4e47c49be5b6c83730cd0f
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ def instrument_client(
that is called right before the span ends
"""

if getattr(client, "_is_instrumented_by_opentelemetry", False):
if getattr(
client._transport, "_is_instrumented_by_opentelemetry", False
):
_logger.warning(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't log a warning if someone instruments a new client with the same transport. So I think we need to keep the attribute and warning on the client, but silently do nothing if the transport is already instrumented.

"Attempting to instrument Httpx client while already instrumented"
)
Expand Down Expand Up @@ -946,7 +948,7 @@ def instrument_client(
response_hook=response_hook,
),
)
client._is_instrumented_by_opentelemetry = True
client._transport._is_instrumented_by_opentelemetry = True
if hasattr(client._transport, "handle_async_request"):
wrap_function_wrapper(
client._transport,
Expand All @@ -972,7 +974,7 @@ def instrument_client(
async_response_hook=async_response_hook,
),
)
client._is_instrumented_by_opentelemetry = True
client._transport._is_instrumented_by_opentelemetry = True

@staticmethod
def uninstrument_client(
Expand All @@ -987,9 +989,9 @@ def uninstrument_client(
unwrap(client._transport, "handle_request")
for transport in client._mounts.values():
unwrap(transport, "handle_request")
client._is_instrumented_by_opentelemetry = False
client._transport._is_instrumented_by_opentelemetry = False
elif hasattr(client._transport, "handle_async_request"):
unwrap(client._transport, "handle_async_request")
for transport in client._mounts.values():
unwrap(transport, "handle_async_request")
client._is_instrumented_by_opentelemetry = False
client._transport._is_instrumented_by_opentelemetry = False
Loading