-
Notifications
You must be signed in to change notification settings - Fork 637
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
- Add example to `opentelemetry-instrumentation-openai-v2` | |||
([#3006](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3006)) | |||
- Support for `AsyncOpenAI/AsyncCompletions` ([#2984](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2984)) | |||
- Add metrics to the Python OpenAI instrumentation ([#3180](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3180)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add metrics to the Python OpenAI instrumentation ([#3180](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3180)) | |
- Add metrics ([#3180](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3180)) |
@@ -23,6 +24,7 @@ | |||
) | |||
from opentelemetry.trace import Span, SpanKind, Tracer | |||
|
|||
from .meters import Meters # Import the Meters class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from .meters import Meters # Import the Meters class | |
from .meters import Meters |
@@ -52,6 +69,62 @@ def fixture_event_logger_provider(log_exporter): | |||
return event_logger_provider | |||
|
|||
|
|||
@pytest.fixture(scope="function", name="meter_provider") | |||
def fixture_meter_provider(metric_reader): | |||
token_usage_histogram_view = View( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am not sure adding the views is useful since it's outside of the instrumentation concern, maybe wait for advisory support to get in instead?
@@ -0,0 +1,38 @@ | |||
OpenTelemetry OpenAI Instrumentation Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there is anything openai specific here, should we document the views more generally instead?
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
- Documentationgen_ai.client.operation.duration
- DocumentationThere 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.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.