-
Notifications
You must be signed in to change notification settings - Fork 800
Description
Describe your environment
OS: Ubuntu in docker
Python version: 3.11
Package version: 0.49b2
What happened?
If the environment variable NO_PROXY is set HTTPXClientInstrumentor.instrument_client(client) will fail when wrapping the mounted transport with wrap_function_wrapper because the transport is None for that mount.
Steps to Reproduce
export NO_PROXY=http://example.comimport httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
with httpx.Client() as client:
HTTPXClientInstrumentor.instrument_client(client)Expected Result
No exception, client is instrumented.
Actual Result
Error in wrapt/patches.py", line 46, in lookup_attribute
AttributeError: 'NoneType' object has no attribute 'handle_request'
Additional context
I had tests that failed only in CircleCI and I traced it to the presence of the environment variable NO_PROXY. HTTPX makes a mount for each entry in NO_PROXY, but with transport set to None.
https://www.python-httpx.org/environment_variables/#no_proxy
CircleCI is where I found this, because CircleCI sets this env var in its base cimg images, probably to ensure curl works. They set it to 127.0.0.1,localhost,circleci-internal-outer-build-agent.
The affected code is
Line 1008 in 54e684a
| wrap_function_wrapper( |
Line 1033 in 54e684a
| wrap_function_wrapper( |
The easiest fix appears to be to skip a mount if transport is None.
There are two workarounds:
- Use
HTTPXClientInstrumentor().instrument()instead ofinstrument_client. - Set
trust_env=Falsewhen creating thehttpx.Clientorhttpx.AsyncClient.httpxwon't use the env variables at all, which affects proxies and ssl key definitions.
Would you like to implement a fix?
None