Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPXClientInstrumentor.instrument_client fails when NO_PROXY is set #3020

Closed
robotadam opened this issue Nov 18, 2024 · 3 comments · Fixed by #3022
Closed

HTTPXClientInstrumentor.instrument_client fails when NO_PROXY is set #3020

robotadam opened this issue Nov 18, 2024 · 3 comments · Fixed by #3022
Labels
bug Something isn't working

Comments

@robotadam
Copy link

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.com
import 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

and

The easiest fix appears to be to skip a mount if transport is None.

There are two workarounds:

  1. Use HTTPXClientInstrumentor().instrument() instead of instrument_client.
  2. Set trust_env=False when creating the httpx.Client or httpx.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

@robotadam robotadam added the bug Something isn't working label Nov 18, 2024
@xrmx
Copy link
Contributor

xrmx commented Nov 18, 2024

Note to self: never touch the httpx instrumentation again 😅

@robotadam
Copy link
Author

Note to self: never touch the httpx instrumentation again 😅

@xrmx 😂 Sorry! Hope this one is easy, at least.

@emdneto
Copy link
Member

emdneto commented Nov 18, 2024

@xrmx @robotadam I'm opening a PR 😅

emdneto added a commit to emdneto/opentelemetry-python-contrib that referenced this issue Nov 18, 2024
Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants