open-telemetry / open-telemetry/opentelemetry-python-genai
Instrument OpenAI structured outputs
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 39
- Forks
- 63
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 175
Description
What problem do you want to solve?
Instrument https://platform.openai.com/docs/guides/structured-outputs?api-mode=chat
Currently this records nothing even when exporters are configured:
import os
import openai
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
from pydantic import BaseModel
os.environ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT'] = 'true'
OpenAIInstrumentor().instrument()
class CalendarEvent(BaseModel):
name: str
date: str
participants: list[str]
completion = openai.beta.chat.completions.parse(
model='gpt-4o-2024-08-06',
messages=[
{'role': 'system', 'content': 'Extract the event information.'},
{'role': 'user', 'content': 'Alice and Bob are going to a science fair on Friday.'},
],
response_format=CalendarEvent,
)
print(completion.choices[0].message.parsed)
Describe the solution you'd like
openai.beta.chat.completions.parse should be instrumented just like openai.chat.completions.create is.
Describe alternatives you've considered
No response
Additional Context
No response
Would you like to implement a fix?
No
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 at OpenAIInstrumentor and trace how openai.chat.completions.create is instrumented. Compare that path with openai.beta.chat.completions.parse, then verify that configured exporters record the structured-output call when message-content capture is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100