Skip to content

fix(ollama): Implemented meter in the instrumentation #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 11, 2025

Conversation

adharshctr
Copy link
Contributor

@adharshctr adharshctr commented Mar 6, 2025

image

  • 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.

Important

Added metrics collection to Ollama instrumentation using histograms for token usage and operation duration.

  • Metrics:
    • Added token_histogram and duration_histogram to track token usage and operation duration in __init__.py.
    • Introduced _create_metrics() to initialize histograms for metrics.
    • Added is_metrics_enabled() to check if metrics collection is enabled.
  • Functions:
    • Updated _wrap() and _awrap() to record metrics using histograms.
    • Modified _set_response_attributes() to record token usage in token_histogram.
    • Updated _accumulate_streaming_response() and _aaccumulate_streaming_response() to pass token_histogram.
  • Instrumentation:
    • Updated OllamaInstrumentor._instrument() to initialize and pass histograms to wrapped methods.

This description was created by Ellipsis for 1276b31. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. new instrumentation labels Mar 6, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to 1276b31 in 3 minutes and 7 seconds

More details
  • Looked at 279 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/__init__.py:446
  • Draft comment:
    Tuple assignment mistake: When metrics are disabled, the tuple is set to three values (None, None, None), while only two (token_histogram, duration_histogram) are expected.
  • Reason this comment was not posted:
    Marked as duplicate.
2. packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/__init__.py:237
  • Draft comment:
    Potential bug: Using 'res' outside the loop in _accumulate_streaming_response may be undefined if the response is empty.
  • Reason this comment was not posted:
    Comment was on unchanged code.
3. packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/__init__.py:237
  • Draft comment:
    Verify the use of the dictionary union operator (res | accumulated_response) in streaming responses. Ensure that the merging behavior is as intended.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50%
    None
4. packages/opentelemetry-instrumentation-ollama/opentelemetry/instrumentation/ollama/__init__.py:241
  • Draft comment:
    The function name '_aaccumulate_streaming_response' contains an extra 'a' at the beginning. Consider renaming it (for example, to '_accumulate_streaming_response_async') to improve readability and follow naming conventions.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_ysXShdjstHS5VGQs


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

adharshctr and others added 6 commits March 6, 2025 12:27
…strumentation/ollama/__init__.py

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
…strumentation/ollama/__init__.py

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Copy link
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adharshctr! Do you mind adding tests for this?

@adharshctr
Copy link
Contributor Author

Thanks @adharshctr! Do you mind adding tests for this?

Added

@adharshctr adharshctr requested a review from nirga March 11, 2025 07:11
@nirga nirga changed the title feat(ollama): Implemented meter in the instrumentation fix(ollama): Implemented meter in the instrumentation Mar 11, 2025
@adharshctr adharshctr requested a review from nirga March 11, 2025 11:05
@nirga nirga merged commit b1fde54 into traceloop:main Mar 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new instrumentation size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants