Closed robotadam closed 2 days ago
Note to self: never touch the httpx instrumentation again :sweat_smile:
Note to self: never touch the httpx instrumentation again š
@xrmx š Sorry! Hope this one is easy, at least.
@xrmx @robotadam I'm opening a PR š
Describe your environment
OS: Ubuntu in docker Python version: 3.11 Package version: 0.49b2
What happened?
If the environment variable
NO_PROXY
is setHTTPXClientInstrumentor.instrument_client(client)
will fail when wrapping the mounted transport withwrap_function_wrapper
because the transport isNone
for that mount.Steps to Reproduce
Expected Result
No exception, client is instrumented.
Actual Result
Error in
wrapt/patches.py", line 46, in lookup_attribute
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 inNO_PROXY
, but with transport set toNone
. https://www.python-httpx.org/environment_variables/#no_proxyCircleCI is where I found this, because CircleCI sets this env var in its base
cimg
images, probably to ensure curl works. They set it to127.0.0.1,localhost,circleci-internal-outer-build-agent
.The affected code is https://github.com/open-telemetry/opentelemetry-python-contrib/blob/54e684aa6985536c8807567c592ea60751d62162/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py#L1008 and https://github.com/open-telemetry/opentelemetry-python-contrib/blob/54e684aa6985536c8807567c592ea60751d62162/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py#L1033
The easiest fix appears to be to skip a mount if
transport
isNone
.There are two workarounds:
HTTPXClientInstrumentor().instrument()
instead ofinstrument_client
.trust_env=False
when creating thehttpx.Client
orhttpx.AsyncClient
.httpx
won't use the env variables at all, which affects proxies and ssl key definitions.Would you like to implement a fix?
None