Skip to content

Instrument embeddings in openai client #14353

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

anuraaga
Copy link
Contributor

No description provided.

@anuraaga anuraaga requested a review from a team as a code owner July 31, 2025 01:50
@@ -50,6 +50,7 @@ public interface GenAiAttributesGetter<REQUEST, RESPONSE> {
@Nullable
Double getRequestTopP(REQUEST request);

@Nullable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We initially had discussion that it's confusing if a list can be empty or null, which was definitely correct for chat. But these semantic conventions are shared between chat / embeddings where ones like this one aren't present at all in embeddings, so I guess we should allow null for it

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the GenAiAttributesExtractor treats null and empty the same way making this nullable isn't strictly necessary. @trask do you have a preference here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - I reverted since indeed the behavior is the same

@steverao steverao requested a review from Copilot July 31, 2025 14:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds telemetry instrumentation for embeddings operations in the OpenAI Java client. It extends the existing chat completion instrumentation to include embeddings, adding telemetry collection for embedding creation requests and responses.

  • Adds instrumentation for OpenAI embeddings API calls
  • Creates test infrastructure and test cases for embeddings operations
  • Implements attribute extraction for embedding-specific metadata

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
testing/src/main/resources/mappings/* Test fixture mappings for embedding API responses
testing/src/main/java/.../Abstract*.java Base test classes and embedding-specific test implementation
library/src/test/java/.../EmbeddingsTest.java Library-specific embeddings test
library/src/main/java/.../OpenAITelemetry*.java Updated telemetry builder and main class to support embeddings
library/src/main/java/.../Instrumented*.java Instrumented client classes updated to handle embeddings services
library/src/main/java/.../InstrumentedEmbedding*.java New embedding service instrumentation classes
library/src/main/java/.../EmbeddingAttributesGetter.java Attribute getter implementation for embeddings
library/src/main/java/.../GenAiAttributes.java Added embeddings operation name constant
javaagent/src/test/java/.../EmbeddingsTest.java JavaAgent-specific embeddings test
instrumentation-api-incubator/.../GenAiAttributesGetter.java Added @nullable annotation

@@ -15,6 +15,7 @@ final class GenAiAttributes {

static final class GenAiOperationNameIncubatingValues {
static final String CHAT = "chat";
static final String EMBEDDING = "embeddings";
Copy link
Member

Choose a reason for hiding this comment

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

maybe a nitpick, but should this be EMBEDDINGS to match the value? Maybe not, since it's singular in all the other class names

.addAttributesExtractor(
GenAiAttributesExtractor.create(EmbeddingAttributesGetter.INSTANCE))
.addOperationMetrics(GenAiClientMetrics.get())
.buildInstrumenter(SpanKindExtractor.alwaysClient());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized I had the wrong span kind. I will fix / assert for chat spans in a separate PR

@anuraaga anuraaga mentioned this pull request Aug 6, 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.

3 participants