Skip to content

Subclassing httpx causing isinstance checks failed #2609

@CNSeniorious000

Description

@CNSeniorious000

Describe your environment

OS: Windows-10-10.0.22631-SP0
Python version: Python 3.12.3
Package version: opentelemetry-instrumentation-httpx="0.46b0"

What happened?

I instrumented httpx after some httpx clients being initialized, and then isinstance(client, Client) failed.

I admit that instrumenting code should ideally be placed before any other code, but I hope that even if it is not done this way, it will result in no errors if possible.

Related to pydantic/logfire#264

Steps to Reproduce

from httpx import Client
client = Client()
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
HTTPXClientInstrumentor().instrument()
from httpx import Client
isinstance(client, Client)

Expected Result

True

Actual Result

False

Additional context

Maybe we can use an non-subclassing approach, like patching methods on the original class.

Would you like to implement a fix?

Being open to

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions