Open CNSeniorious000 opened 1 week ago
I can reproduce with this code:
import httpx
import openai
import logfire
logfire.configure()
client = httpx.AsyncClient()
logfire.instrument_httpx()
openai.AsyncClient(http_client=client, api_key='...')
The error doesn't happen if client = httpx.AsyncClient()
is done after logfire.instrument_httpx()
. What's happening is that logfire.instrument_httpx
replaces the class httpx.AsyncClient
with its own subclass, so when openai checks isinstance(http_client, httpx.AsyncClient)
it fails because now http_client
is an instance of the original class while httpx.AsyncClient
is a subclass of the original.
This should be reported to OTEL.
I see. Thanks for your clear explanation. I should instrument_httpx after any httpx instance initialized. But maybe I think OTEL can't instrument httpx without subclassing it?
No, you should call instrument_httpx
before constructing the client. In fact you should do that anyway if you want the client to be instrumented.
OTEL could instrument httpx without subclassing, e.g. by patching the __init__
method on the original class.
Yeah thanks. I made a typos mistake.
I've refactored my code and openai works well with httpx now. I am going to post an issue to OTEL now. Thanks for your reproduction example
Description
If I use
instrument_httpx()
, and then construct an OpenAI client with a custom httpx client, openai will raise an TypeError:Python, Logfire & OS Versions, related packages (not required)