Skip to content
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

Add metrics to the Python OpenAI instrumentation #3180

Merged
merged 18 commits into from
Jan 15, 2025

Conversation

drewby
Copy link
Member

@drewby drewby commented Jan 10, 2025

Description

This PR implements the GenAI semantic conventions for the two client metrics so they are collected along with spans when instrumenting a Python application.

Basic implementation of two client metrics defined in the GenAI semantic conventions:

gen_ai.client.token.usage - Documentation
gen_ai.client.operation.duration - Documentation

There is an example added to show end users who to configure the explicit bucket boundaries as defined in the semantic convention spec.

Fixes #3177

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • test_chat_completion_metrics - tests that metrics are correctly emitted when calling OpenAI synchronously.
  • test_async_chat_completion_metrics - tests that metrics are correctly emitted when calling OpenAI asynchronously.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

A couple of nits but LGTM. Not sure that setting the views for having proper buckets it's useful but no big deal.

Copy link
Contributor

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

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

Looks great, just a few comments on recording errors

@lzchen lzchen merged commit a716949 into open-telemetry:main Jan 15, 2025
675 checks passed
xrmx pushed a commit to xrmx/opentelemetry-python-contrib that referenced this pull request Jan 24, 2025
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.

Add metrics to the Python OpenAI instrumentation
9 participants