Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<version>${revision}</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-observation-extension</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,37 @@
*/
package com.alibaba.cloud.ai.autoconfigure.arms;

import com.alibaba.cloud.ai.observation.client.prompt.PromptMetadataAwareChatClientObservationConvention;
import com.alibaba.cloud.ai.observation.model.ChatModelInputObservationHandler;
import com.alibaba.cloud.ai.observation.model.ChatModelOutputObservationHandler;
import com.alibaba.cloud.ai.observation.model.PromptMetadataAwareChatModelObservationConvention;
import com.alibaba.cloud.ai.tool.ObservableToolCallingManager;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.chat.client.observation.ChatClientObservationConvention;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
import org.springframework.ai.model.tool.ToolCallingManager;
import org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor;
import org.springframework.ai.tool.resolution.ToolCallbackResolver;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
* @author Lumian
*/
@AutoConfiguration
@ConditionalOnClass(ChatModel.class)
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true")
@EnableConfigurationProperties(ArmsCommonProperties.class)
public class ArmsAutoConfiguration {

@Bean
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "tool.enabled", havingValue = "true")
ToolCallingManager toolCallingManager(ToolCallbackResolver toolCallbackResolver,
ToolExecutionExceptionProcessor toolExecutionExceptionProcessor,
ObjectProvider<ObservationRegistry> observationRegistry) {
Expand All @@ -45,4 +56,32 @@ ToolCallingManager toolCallingManager(ToolCallbackResolver toolCallbackResolver,
.build();
}

@Bean
ChatClientObservationConvention chatClientObservationConvention() {
return new PromptMetadataAwareChatClientObservationConvention();
}

@Bean
ChatModelObservationConvention chatModelObservationConvention() {
return new PromptMetadataAwareChatModelObservationConvention();
}

@Bean
@ConditionalOnMissingBean(value = { ChatModelInputObservationHandler.class },
name = { "chatModelInputObservationHandler" })
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "model.capture-input",
havingValue = "true")
ChatModelInputObservationHandler armsChatModelInputObservationHandler(ArmsCommonProperties properties) {
return new ChatModelInputObservationHandler(properties.getModel().getMessageMode());
}

@Bean
@ConditionalOnMissingBean(value = { ChatModelOutputObservationHandler.class },
name = { "chatModelOutputObservationHandler" })
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "model.capture-output",
havingValue = "true")
ChatModelOutputObservationHandler armsChatModelOutputObservationHandler(ArmsCommonProperties properties) {
return new ChatModelOutputObservationHandler(properties.getModel().getMessageMode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.alibaba.cloud.ai.autoconfigure.arms;

import com.alibaba.cloud.ai.observation.model.semconv.MessageMode;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
Expand All @@ -33,6 +34,10 @@ public class ArmsCommonProperties {
*/
private boolean enabled = false;

private ModelProperties model = new ModelProperties();

private ToolProperties tool = new ToolProperties();

public boolean isEnabled() {
return enabled;
}
Expand All @@ -41,4 +46,77 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public ModelProperties getModel() {
return model;
}

public void setModel(ModelProperties model) {
this.model = model;
}

public ToolProperties getTool() {
return tool;
}

public void setTool(ToolProperties tool) {
this.tool = tool;
}

public static class ModelProperties {

/**
* Enable Arms instrumentations and conventions.
*/
private boolean captureInput = false;

/**
* Enable Arms instrumentations and conventions.
*/
private boolean captureOutput = false;

/**
* Arms export type enumeration.
*/
private MessageMode messageMode = MessageMode.OPEN_TELEMETRY;

public boolean isCaptureInput() {
return captureInput;
}

public void setCaptureInput(boolean captureInput) {
this.captureInput = captureInput;
}

public boolean isCaptureOutput() {
return captureOutput;
}

public void setCaptureOutput(boolean captureOutput) {
this.captureOutput = captureOutput;
}

public MessageMode getMessageMode() {
return messageMode;
}

public void setMessageMode(MessageMode messageMode) {
this.messageMode = messageMode;
}

}

public static class ToolProperties {

private boolean enabled = true;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}

}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<module>spring-ai-alibaba-jmanus</module>
<module>spring-ai-alibaba-deepresearch</module>

<!-- Spring AI Alibaba Extension Modules -->
<module>spring-ai-alibaba-observation-extension</module>

<!-- Spring AI Alibaba Tool Call Plugins -->
<module>community/tool-calls/spring-ai-alibaba-starter-tool-calling-common</module>
<module>community/tool-calls/spring-ai-alibaba-starter-tool-calling-time</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ protected KeyValues toolDescription(KeyValues keyValues, ArmsToolCallingObservat

protected KeyValues toolParameters(KeyValues keyValues, ArmsToolCallingObservationContext context) {
if (context.getToolCall().arguments() != null) {
return keyValues.and(HighCardinalityKeyNames.TOOL_PARAMETERS.asString(), context.getToolCall().arguments());
return keyValues.and(HighCardinalityKeyNames.TOOL_PARAMETERS.asString(), context.getToolCall().arguments())
.and(HighCardinalityKeyNames.INPUT_VALUE.asString(), context.getToolCall().arguments());
}
return keyValues;
}
Expand Down
95 changes: 95 additions & 0 deletions spring-ai-alibaba-observation-extension/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024-2025 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-ai-alibaba-observation-extension</artifactId>
<version>${revision}</version>
<packaging>jar</packaging>
<name>Spring AI Alibaba Observation Extension</name>
<description>Spring AI Alibaba Observation Extension Module, ARMS Implementation</description>

<url>https://github.com/alibaba/spring-ai-alibaba</url>

<scm>
<connection>git://github.com/alibaba/spring-ai-alibaba.git</connection>
<developerConnection>git@github.com:alibaba/spring-ai-alibaba.git</developerConnection>
<url>https://github.com/alibaba/spring-ai-alibaba</url>
</scm>

<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-model</artifactId>
</dependency>

<!-- FIXME: remove dependencies to openai -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-client-chat</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-commons</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Loading
Loading