Skip to content

Conversation

@Cirilla-zmh
Copy link
Member

@Cirilla-zmh Cirilla-zmh commented Oct 20, 2025

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.

Change-Id: Iba625f3b4a0c5528c86d83e42a1a884b2e139fd7

Change-Id: I94b2d7d49d68e720b7637d73f5de973640cd13a6
@Cirilla-zmh Cirilla-zmh requested a review from a team as a code owner October 20, 2025 16:36
@Cirilla-zmh Cirilla-zmh marked this pull request as draft October 20, 2025 16:38
@otelbot-java-instrumentation
Copy link
Contributor

🔧 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> {
Copy link
Member Author

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);
Copy link
Member Author

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) {
Copy link
Member Author

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 {
Copy link
Member Author

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")
Copy link
Member Author

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))
Copy link
Member Author

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"))
Copy link
Member Author

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);
Copy link
Member Author

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";
Copy link
Member Author

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'.

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.

1 participant