open-telemetry / open-telemetry/opentelemetry-python-contrib
Completion Tokens and Thinking Tokens in OpenAIv2 Instrumentation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
What problem do you want to solve?
The semconv and spans generated by the openai instrumentation include input tokens and output tokens. These are a great start, but I would like to propose adding completion tokens to these as well.
Completion tokens are a very important piece of information for debugging and evaluating agentic systems. Efficient prompt usage is an important element when building agent systems and optimizing cost.
Describe the solution you'd like
I would like to add a new attribute gen_ai.usage.cached_tokens to the span generated by the openai instrumentation. The cached tokens can be populated from the Completion object returned by the API.
My guess is this would need to be added into the gen-ai semantic conventions. I think a case could be made that completion tokens could fit into the semantic conventions since other providers also have some concept of completions tokens.
Describe alternatives you've considered
No response
Additional Context
No response
Would you like to implement a fix?
None
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
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 by locating the OpenAIv2 instrumentation and reviewing the linked GenAI semantic conventions and OpenAI Completion object documentation. Clarify whether cached, completion, and thinking tokens are in scope, then determine how the selected attribute should be represented in generated spans and what instrumentation behavior would verify completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100