Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
This commit a7ebc26, which was introduced in PR #966, for release v1.3.9, disables httpx instrumentation in some cases.
Specifically, it is disabled when openai is imported before instrumenting httpx.
This is because opentelemetry.instrumentation.httpx .HTTPXClientInstrumentor._instrument
creates subclasses of httpx.Client
and httpx.AsyncClient
. And then replaces the original clients with those subclasses, which adds telemetry.
In the above commit, openai creates SyncHttpxClientWrapper
and AsyncHttpxClientWrapper
subclasses of httpx's clients.
That means that when we instrument first, and then import openai, the client wrappers inherit from the instrumented clients.
When we import openai first, and then instrument httpx, the wrapper clients inherit from the original httpx clients.
Maybe this should be addressed at the opentelemetry-python-contrib side, but even so, v1.3.9 broke telemetry.
Could the change implemented in #966 be implemented in a backward-compatible way?
If not, at the very least, the changelog should be updated, warning about this.
To Reproduce
- Import openai
- Use
HTTPXClientInstrumentor
fromopentelemetry.instrumentation.httpx
to instrument httpx.
Code snippets
Running this, openai httpx requests are instrumented:
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor, _InstrumentedClient
HTTPXClientInstrumentor().instrument()
from openai._base_client import SyncHttpxClientWrapper
assert issubclass(SyncHttpxClientWrapper, _InstrumentedClient)
But this version is not instrumented, and the assertion fails:
from openai._base_client import SyncHttpxClientWrapper
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor, _InstrumentedClient
HTTPXClientInstrumentor().instrument()
assert issubclass(SyncHttpxClientWrapper, _InstrumentedClient)
OS
any
Python version
any
Library version
openai from v1.3.9.0 to v1.12.0