pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://logfire.pydantic.dev/docs/
MIT License
2.14k stars 64 forks source link

`logfire.instrument_httpx()` breaks OpenAI SDK #529

Open samuelcolvin opened 2 weeks ago

samuelcolvin commented 2 weeks ago

Description

Once I've run

logfire.instrument_httpx()

if I then try to create an OpenAI client I get

  File "/Users/samuel/code/.../.venv/lib/python3.12/site-packages/openai/_client.py", line 337, in __init__
    super().__init__(
  File "/Users/samuel/code/.../.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1420, in __init__
    raise TypeError(
TypeError: Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got <class 'httpx.AsyncClient'>

This is not our fault, but we could create a PR to OpenAI to try to fix it.

We should also allow

logfire.instrument_httpx(client)

So you can easily instrument one client but not all.

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

logfire="1.2.0"
platform="macOS-14.6.1-arm64-arm-64bit"
python="3.12.6 (main, Sep 20 2024, 17:42:55) [Clang 15.0.0 (clang-1500.0.40.1)]"
[related_packages]
requests="2.32.3"
pydantic="2.9.2"
openai="1.51.2"
protobuf="4.25.5"
rich="13.9.2"
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-httpx="0.48b0"
opentelemetry-proto="1.27.0"
opentelemetry-sdk="1.27.0"
opentelemetry-semantic-conventions="0.48b0"
opentelemetry-util-http="0.48b0"
Kludex commented 2 weeks ago

How our tests didn't get this? 🤔

Can we use VCR instead of mocking things?

alexmojaki commented 2 weeks ago

Duplicate of https://github.com/pydantic/logfire/issues/264 and https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2609

alexmojaki commented 2 weeks ago

https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2364#issuecomment-2429551345

alexmojaki commented 5 days ago

This is supposedly fixed now in OTEL contrib, we need to check when they next release, but nothing needs to be done on our side for now.