Open bastbu opened 1 month ago
Thanks for reporting @bastbu! You mentioned you'd like to issue a fix - would love that if you have time! If not let me know and we'll take care of it. Let me know if you need guidance / assistance.
Thanks @nirga! I realized that the fix is a little bit more involved than I originally anticipated, due to the differences in the non-streaming and streaming cases.
It'd probably take me a while before I get the time to attempt a proper fix for this. Hence, if you'd want to take care of it, that may be better.
Which component is this bug for?
OpenAI Instrumentation
📜 Description
When having
httpx
instrumentation enabled, thePOST
span to the chat completions endpoint does not haveopenai.chat
as a parent.1541 reports a similar behavior for the Langchain instrumentation.
👟 Reproduction steps
opentelemetry-instrumentation-httpx
andopentelemetry-instrumentation-openai
👍 Expected behavior
The POST request should have
openai.chat
as a parent.👎 Actual Behavior with Screenshots
The
httpx
span and theopenai.chat
span have the same parent.🤖 Python Version
3.11
📃 Provide any additional context for the Bug.
The spans appear not to be consistently set as the currently active span when starting:
https://github.com/traceloop/openllmetry/blob/fe2393a31cdb307d3638c8995a907f846e8befec/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py#L70-L74
versus
https://github.com/traceloop/openllmetry/blob/fe2393a31cdb307d3638c8995a907f846e8befec/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py#L58-L62
👀 Have you spent some time to check if this bug has been raised before?
Are you willing to submit PR?
Yes I am willing to submit a PR!