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

httpx instrumentation issue with authlib #478

Open
rmasters opened this issue Oct 6, 2024 · 0 comments
Open

httpx instrumentation issue with authlib #478

rmasters opened this issue Oct 6, 2024 · 0 comments
Labels
Bug Bug related to the Logfire Python SDK

Comments

@rmasters
Copy link

rmasters commented Oct 6, 2024

Description

I have an instrumentation issue with an application that uses Authlib to connect with an external API. I'm using the Async variant of Authlib, which uses httpx rather than requests.

This appears to be a problem with the upstream opentelemetry project (already reported in open-telemetry/opentelemetry-python-contrib#2364), but I thought I'd report here for your awareness and searchability, as I encountered it through logfire.instrument_httpx() - please feel free to close.

I'm able to work around this for now by disabling the instrumentation. If there are any options to disable instrumentation, temporarily or for specific classes, that could be helpful.


I see the following exception when running under logfire:

  File "/app/myapp/services/some_api.py", line 23, in from_credentials
    client = AsyncOAuth2Client(
             ^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/authlib/integrations/httpx_client/oauth2_client.py", line 65, in __init__
    httpx.AsyncClient.__init__(self, **client_kwargs)
  File "/app/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/httpx/__init__.py", line 678, in __init__
    super().__init__(*args, **kwargs)
    ^^^^^^^^^^^^^^^^
TypeError: super(type, obj): obj must be an instance or subtype of type

This happens because Authlib inherits from httpx.AsyncClient:

# authlib/integrations/httpx_client/oauth2_client.py
class AsyncOAuth2Client(_OAuth2Client, httpx.AsyncClient):
    def __init__(self, ...snip...):
       ...snip...
        httpx.AsyncClient.__init__(self, **client_kwargs)

       ...snip...
        _OAuth2Client.__init__(self, ...snip...)

There's a more complete code-sample in the opentelemetry issue, although in my case I'm not using HTTPXClientInstrumentor directly, just logfire.instrument_httpx.

To replicate locally, my environment has:

dependencies = [
    "httpx>=0.27.2",
    "authlib>=1.3.2",
    "logfire[fastapi,httpx,sqlalchemy]>=1.0.1",
]

$ uv export | grep logfire
Resolved 106 packages in 1ms
logfire==1.0.1 \
$ uv export | grep httpx
httpx==0.27.2 \
opentelemetry-instrumentation-httpx==0.48b0 \
$ uv export | grep authlib
authlib==1.3.2 \

Python, Logfire & OS Versions, related packages (not required)

logfire="1.0.1"
platform="Linux-6.1.0-25-amd64-x86_64-with-glibc2.36"
python="3.12.7 (main, Oct  1 2024, 22:28:49) [GCC 12.2.0]"
[related_packages]
requests="2.32.3"
pydantic="2.9.0"
fastapi="0.115.0"
protobuf="4.25.5"
rich="13.8.0"
executing="2.1.0"
opentelemetry-api="1.27.0"
opentelemetry-exporter-otlp-proto-common="1.27.0"
opentelemetry-exporter-otlp-proto-http="1.27.0"
opentelemetry-instrumentation="0.48b0"
opentelemetry-instrumentation-asgi="0.48b0"
opentelemetry-instrumentation-fastapi="0.48b0"
opentelemetry-instrumentation-httpx="0.48b0"
opentelemetry-instrumentation-sqlalchemy="0.48b0"
opentelemetry-proto="1.27.0"
opentelemetry-sdk="1.27.0"
opentelemetry-semantic-conventions="0.48b0"
opentelemetry-util-http="0.48b0"
@rmasters rmasters added the Bug Bug related to the Logfire Python SDK label Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug related to the Logfire Python SDK
Projects
None yet
Development

No branches or pull requests

1 participant