traceloop / traceloop/openllmetry
๐ Bug Report: OpenAI spans are not always started as current span
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.4k
- Forks
- 1.1k
- Avg merge
- 8d 14h
- Merged PRs (30d)
- 2
Description
Which component is this bug for?
OpenAI Instrumentation
๐ Description
When having httpx instrumentation enabled, the POST span to the chat completions endpoint does not have openai.chat as a parent.
#1541 reports a similar behavior for the Langchain instrumentation.
๐ Reproduction steps
- Use
opentelemetry-instrumentation-httpxandopentelemetry-instrumentation-openai - Send a chat completions request
๐ Expected behavior
The POST request should have openai.chat as a parent.
๐ Actual Behavior with Screenshots
The httpx span and the openai.chat span have the same parent.
{
"name": "POST",
"context": {
"trace_id": "0x8252aa8e6eab7da39677aeb684257982",
"span_id": "0xbbb358e3bb731dda",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": "0x174f1749b1e29d48",
"start_time": "2024-07-12T05:54:09.501887Z",
"end_time": "2024-07-12T05:54:10.174165Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"http.method": "POST",
"http.url": "<redacted>",
"http.status_code": 200
},
"events": [],
"links": [],
"resource": {
"attributes": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.25.0",
"service.name": "unknown_service"
},
"schema_url": ""
}
}
{
"name": "openai.chat",
"context": {
"trace_id": "0x8252aa8e6eab7da39677aeb684257982",
"span_id": "0x7a611da25eb9b760",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": "0x174f1749b1e29d48",
"start_time": "2024-07-12T05:54:09.490627Z",
"end_time": "2024-07-12T05:54:10.246270Z",
"status": {
"status_code": "OK"
},
"attributes": {
"llm.request.type": "chat",
"gen_ai.system": "OpenAI",
"gen_ai.request.model": "gpt-35-turbo",
"llm.headers": "None",
"llm.is_streaming": true,
"gen_ai.openai.api_base": "<redacted>",
"gen_ai.openai.api_version": "2023-07-01-preview",
"gen_ai.response.model": "gpt-35-turbo"
},
"events": [],
"links": [],
"resource": {
"attributes": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.25.0",
"service.name": "unknown_service"
},
"schema_url": ""
}
}
๐ค 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:
versus
๐ Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
Yes I am willing to submit a PR!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up โ it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the referenced chat_wrappers.py and embeddings_wrappers.py sections, comparing how each span is made the current active span. Reproduce the issue with httpx and OpenAI instrumentation while sending a chat completions request. Done means the httpx POST span has openai.chat as its parent, rather than sharing its parent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100