-
Notifications
You must be signed in to change notification settings - Fork 1k
Draft: init spring-ai instrumentation #15064
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
Change-Id: Iba625f3b4a0c5528c86d83e42a1a884b2e139fd7 Change-Id: I94b2d7d49d68e720b7637d73f5de973640cd13a6
|
🔧 The result from spotlessApply was committed to the PR branch. |
| import io.opentelemetry.instrumentation.api.genai.messages.ToolDefinitions; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public interface GenAiMessagesProvider<REQUEST, RESPONSE> { |
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.
Implementing this interface for gen-ai instrumentation to capture there messages-related attributes/events.
| internalSet(attributes, GEN_AI_OUTPUT_MESSAGES, toJsonString(outputMessages.getSerializableObject())); | ||
| } | ||
| } else if (CaptureMessageStrategy.EVENT.equals(messageCaptureOptions.captureMessageStrategy())) { | ||
| emitInferenceEvent(context, request, response); |
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 have to emit event on end, because only here we could access all of attributes we need.
| } | ||
|
|
||
| @Override | ||
| public String extract(REQUEST request) { |
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.
Let's make it more generic!
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
|
|
||
| public final class AgentIncubatingAttributes { |
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.
Need to update semantic-conventions dep for newest attribute keys. (Maybe there're something wrong with my IDE. I couldn't find these attributes. Let me research more...)
| @@ -0,0 +1,3 @@ | |||
| plugins { | |||
| id("otel.javaagent-bootstrap") | |||
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.
TODO: need to add a new instrumentation
| .getBoolean("otel.instrumentation.genai.capture-message-content", true)) | ||
| .setContentMaxLength( | ||
| InstrumentationConfig.get() | ||
| .getInt("otel.instrumentation.genai.message-content.max-length", 8192)) |
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.
Define the max length of each text message. It would be truncated once over this limit. According to Instrumentations MAY provide a way for users to filter or truncate output messages.
| .getInt("otel.instrumentation.genai.message-content.max-length", 8192)) | ||
| .setCaptureMessageStrategy( | ||
| InstrumentationConfig.get() | ||
| .getString("otel.instrumentation.genai.message-content.capture-strategy", "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.
The value is an enumeration of "span-attributes" and "event". According to Application developers should choose an appropriate usage pattern based on application needs and maturity.
| if (messageCaptureOptions.captureMessageContent()) { | ||
| return ToolDefinition.create(type, name, toolCallback.getToolDefinition().description(), null); | ||
| } else { | ||
| return ToolDefinition.create(type, name, null, null); |
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.
If 'capture-message-content' is disabled, let's capture the 'type' and 'name' only.
|
|
||
| @Override | ||
| public String getOperationName(ChatClientRequest request) { | ||
| return "invoke_agent"; |
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.
Should the ChatClient be considered as an agent? For me it's actually a simple Re-Act agent without other detailed metadata like 'agent name' or 'agent id'.
Add instrumentation for spring-ai and spring-ai-openai.
P.S. This PR is for SIG discussion only. There are still some issues that need to be resolved before submitting a formal PR.