-
Notifications
You must be signed in to change notification settings - Fork 701
Add OpenAI embeddings instrumentation #3461
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
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.
thank you!!!
...opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py
Outdated
Show resolved
Hide resolved
...opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py
Outdated
Show resolved
Hide resolved
# Emit input event | ||
input_event_attributes = { | ||
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value, | ||
EventAttributes.EVENT_NAME: "gen_ai.embeddings.input", |
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'd postpone defining any new events until we have clarity on open-telemetry/semantic-conventions#2010
Also why not gen_ai.user.message
?
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.
Recording inputs/outputs is a fundamental feature we discussed, so I think we need to record as something. The current implementation for chat completions is events, so that would be the most consistent until we decide on 2010. If the decision is to move to attributes, we are going to need to do breaking change PR anyway.
I could reuse the existing event name, but its not really a user message
in the same way as text completions.
|
||
output_event_attributes = { | ||
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value, | ||
EventAttributes.EVENT_NAME: "gen_ai.embeddings.output", |
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.
see my prev comment, I'd rather not define any new events for now
...opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py
Outdated
Show resolved
Hide resolved
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value, | ||
GenAIAttributes.GEN_AI_REQUEST_MODEL: span_attributes[ | ||
GenAIAttributes.GEN_AI_REQUEST_MODEL | ||
], | ||
} | ||
|
||
if "gen_ai.embeddings.dimensions" in span_attributes: |
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.
we can't use span attributes to record metrics - spans are sampled and won't have any attributes when sampled out.
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.
The parameter is called span_attributes, but it is from the previous PR.
Its just a dictionary created during the request by chat_completions_create
and now embeddings_create
, so not subject to sampling. I renamed it here in _record_metrics to just request_attributes
for clarity. If needed, I can rename it in the create methods for better readability as well.
Description
This PR adds instrumentation for OpenAI's embeddings API in the GenAI instrumentation suite. The implementation follows the OpenTelemetry semantic conventions for generative AI systems and provides automatic instrumentation for the OpenAI Python client when using embeddings functionality.
The implementation captures important metadata about embedding operations including model, dimensions, and relevant timing information while respecting sensitive data handling practices.
ai.embedding.dimensions
- Number of dimensions in the embedding vectorsai.embedding.encoding_format
- The encoding format of the embedding vectors response (base64 or float)embeddings
Type of change
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.