-
Notifications
You must be signed in to change notification settings - Fork 628
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 does not work on classes that extend httpx client #2364
Comments
I believe one solution could be to monkeypatch the |
Aaron noted that the httpx instrumentation isn't using wrapt. I'll experiment with that change and see if that improves this. |
Would be good to update the sphinx docs and/or readme |
@jeremydvoss somewhat related: https://docs.python.org/3/library/unittest.mock.html#where-to-patch describes monkey patches not taking effect for tests. Looking at the httpx instrumentation code, we are very naiively monkey patching the httpx module Lines 569 to 570 in 37aba92
Which means like you mentioned, anyone who uses a As a general principle for instrumentation taking effect, that seems better (maybe we can jot this down somewhere). I'm definitely open to re-implementing the pathcing to make this more robust. |
Using wrapt seems like a better approach than what I propsed. Please let me know if you need any help. |
This is also an issue for the HTTPX clients defined by Authlib: https://github.com/lepture/authlib/blob/master/authlib/integrations/httpx_client/oauth2_client.py |
OMG! I just ran into this issue!!! Luckily in our QA environment! here is a simple code sample, in case it helps:
Here is the exception:
|
We are also encountering this. It seems broken that a library would depend on import order. Is there any way to fix this elegantly? |
Another issue that would be fixed by avoiding subclassing: #2609 |
Anyone want to give #2909 a try? |
Would be great if a release could be cut for this. It would clean up our code a ton. |
Becuase the HttpX instrumentation changes the httpx.client class, it does not work on classes that are defined on import (even if the class is only instantiated after instrumentation). This means that as soon as OpenAI created an extension of the HttpX client, the httpx instrumentation stopped working. This could be fixed in OpenAI by defining the class at runtime:
This could also be solved by instrumenting httpx even before importing any library that uses httpx. However, I think these restrictions mean that the HttpX instrumentation is too fragile. We need to improve it so that it works intuitively for all such scenarios.
Describe your environment
Windows
opentelemetry-api 1.23.0
opentelemetry-instrumentation 0.44b0
opentelemetry-instrumentation-httpx 0.44b0
opentelemetry-instrumentation-openai 0.14.1
opentelemetry-sdk 1.23.0
opentelemetry-semantic-conventions 0.44b0
opentelemetry-semantic-conventions-ai 0.0.23
opentelemetry-util-http 0.44b0
Steps to reproduce
What is the expected behavior?
api.openai.com POST should be captured. Note that this is separate from the openai.chat span captured by the openai instrumentation.
What is the actual behavior?
Only the httpx example span and openai.chat spans are collected.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: