Skip to content

feat(instrumentation-ollama): add duration telemetry span attributes#4194

Open
Saptami191 wants to merge 1 commit into
traceloop:mainfrom
Saptami191:add-ollama-duration-telemetry
Open

feat(instrumentation-ollama): add duration telemetry span attributes#4194
Saptami191 wants to merge 1 commit into
traceloop:mainfrom
Saptami191:add-ollama-duration-telemetry

Conversation

@Saptami191
Copy link
Copy Markdown

@Saptami191 Saptami191 commented May 26, 2026

Summary

Adds Ollama duration-related response metadata as tracing span attributes.

Added attributes:

  • llm.ollama.total_duration
  • llm.ollama.load_duration
  • llm.ollama.prompt_eval_duration
  • llm.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

  • 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.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(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.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

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 b39151b and cb1f00b.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/span_utils.py
  • packages/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

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Saptami191
Copy link
Copy Markdown
Author

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants