feat(instrumentation-ollama): add duration telemetry span attributes
Summary
Adds Ollama duration-related response metadata as tracing span attributes.
Added attributes:
llm.ollama.total_durationllm.ollama.load_durationllm.ollama.prompt_eval_durationllm.ollama.eval_duration
Changes
- Extended
set_model_response_attributes()to capture duration telemetry fields from Ollama responses - Added tracing assertions for generation and streaming generation tests
Verification
Verified locally through exported span output.
Example observed Ollama response fields:
{
"total_duration": 115588345200,
"load_duration": 53118691900,
"prompt_eval_duration": 48132531100,
"eval_duration": 13506373700
}
These values are now exported as tracing span attributes.
Checklist
- [x] I have added tests that cover my changes.
- [ ] If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
- [x] PR name follows conventional commits format:
feat(instrumentation): ...orfix(instrumentation): .... - [ ] (If applicable) I have updated the documentation accordingly.
Summary by CodeRabbit
-
New Features
- Ollama instrumentation now captures four additional timing metrics in distributed traces: total duration, load duration, prompt evaluation duration, and evaluation duration. This enhancement provides deeper insight into model execution performance and resource utilization during inference operations.
-
Tests
- Added comprehensive test coverage to verify these new duration metrics are captured accurately and contain valid timing values.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7cd09404-3b9b-4ad6-be8e-39048bde129f
π₯ Commits
Reviewing files that changed from the base of the PR and between b39151bc4d9be6d4a7bb2189fef3b20f8a577156 and cb1f00b1bfa614c7895c22a83085b32d6ca711c4.
π Files selected for processing (2)
packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/span_utils.pypackages/opentelemetry-instrumentation-ollama/tests/test_generation.py
π Walkthrough
Walkthrough
This PR extends Ollama instrumentation by recording four timing metrics as span attributes. The implementation extracts duration values (total, load, prompt evaluation, and inference evaluation) from the Ollama API response and sets them as OpenTelemetry span attributes. Tests verify these attributes are captured and contain non-zero values.
Changes
Ollama Duration Span Attributes
| Layer / File(s) | Summary |
|---|---|
Ollama duration span attributes and test coverage packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/span_utils.py, packages/opentelemetry-instrumentation-ollama/tests/test_generation.py |
set_model_response_attributes sets four new span attributes (llm.ollama.total_duration, llm.ollama.load_duration, llm.ollama.prompt_eval_duration, llm.ollama.eval_duration) from the response object. Tests verify these attributes are present and non-zero in both legacy generation and legacy streaming generation scenarios. |
Estimated code review effort
π― 2 (Simple) | β±οΈ ~8 minutes
Possibly related issues
- traceloop/openllmetry#4192: Implements the exact Ollama duration span attributes requested, directly addressing the feature in the related issue.
Poem
π° Four timers ticked and found their place, Duration metrics now embrace, The Ollama span so bright and true, From load to eval, metrics shrew! β¨
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title clearly and specifically describes the main change: adding duration telemetry span attributes to Ollama instrumentation, which matches the changeset exactly. |
| Linked Issues check | β Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | β Passed | Check skipped because no linked issues were found for this pull request. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Before
{
"llm.provider": "ollama",
"llm.model": "llama3"
}
After
{
"llm.provider": "ollama",
"llm.model": "llama3",
"llm.ollama.total_duration": 115588345200,
"llm.ollama.load_duration": 53118691900,
"llm.ollama.prompt_eval_duration": 48132531100,
"llm.ollama.eval_duration": 13506373700
}