Skip to content

Commit 2b91503

Browse files
Sunriseaco63oc
authored andcommitted
fix(studio): cherry-pick alibaba#2358, support observability of saa studio (alibaba#2447)
1 parent ab6dea2 commit 2b91503

File tree

17 files changed

+1017
-2
lines changed

17 files changed

+1017
-2
lines changed

auto-configurations/spring-ai-alibaba-autoconfigure-arms-observation/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
<version>${revision}</version>
2727
</dependency>
2828

29+
<dependency>
30+
<groupId>com.alibaba.cloud.ai</groupId>
31+
<artifactId>spring-ai-alibaba-observation-extension</artifactId>
32+
<version>${revision}</version>
33+
</dependency>
34+
2935
<dependency>
3036
<groupId>org.springframework.boot</groupId>
3137
<artifactId>spring-boot-starter</artifactId>

auto-configurations/spring-ai-alibaba-autoconfigure-arms-observation/src/main/java/com/alibaba/cloud/ai/autoconfigure/arms/ArmsAutoConfiguration.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,37 @@
1515
*/
1616
package com.alibaba.cloud.ai.autoconfigure.arms;
1717

18+
import com.alibaba.cloud.ai.observation.client.prompt.PromptMetadataAwareChatClientObservationConvention;
19+
import com.alibaba.cloud.ai.observation.model.ChatModelInputObservationHandler;
20+
import com.alibaba.cloud.ai.observation.model.ChatModelOutputObservationHandler;
21+
import com.alibaba.cloud.ai.observation.model.PromptMetadataAwareChatModelObservationConvention;
1822
import com.alibaba.cloud.ai.tool.ObservableToolCallingManager;
1923
import io.micrometer.observation.ObservationRegistry;
24+
import org.springframework.ai.chat.client.observation.ChatClientObservationConvention;
2025
import org.springframework.ai.chat.model.ChatModel;
26+
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
2127
import org.springframework.ai.model.tool.ToolCallingManager;
2228
import org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor;
2329
import org.springframework.ai.tool.resolution.ToolCallbackResolver;
2430
import org.springframework.beans.factory.ObjectProvider;
2531
import org.springframework.boot.autoconfigure.AutoConfiguration;
2632
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
33+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2734
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2835
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2936
import org.springframework.context.annotation.Bean;
3037

38+
/**
39+
* @author Lumian
40+
*/
3141
@AutoConfiguration
3242
@ConditionalOnClass(ChatModel.class)
43+
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true")
3344
@EnableConfigurationProperties(ArmsCommonProperties.class)
3445
public class ArmsAutoConfiguration {
3546

3647
@Bean
37-
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true")
48+
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "tool.enabled", havingValue = "true")
3849
ToolCallingManager toolCallingManager(ToolCallbackResolver toolCallbackResolver,
3950
ToolExecutionExceptionProcessor toolExecutionExceptionProcessor,
4051
ObjectProvider<ObservationRegistry> observationRegistry) {
@@ -45,4 +56,32 @@ ToolCallingManager toolCallingManager(ToolCallbackResolver toolCallbackResolver,
4556
.build();
4657
}
4758

59+
@Bean
60+
ChatClientObservationConvention chatClientObservationConvention() {
61+
return new PromptMetadataAwareChatClientObservationConvention();
62+
}
63+
64+
@Bean
65+
ChatModelObservationConvention chatModelObservationConvention() {
66+
return new PromptMetadataAwareChatModelObservationConvention();
67+
}
68+
69+
@Bean
70+
@ConditionalOnMissingBean(value = { ChatModelInputObservationHandler.class },
71+
name = { "chatModelInputObservationHandler" })
72+
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "model.capture-input",
73+
havingValue = "true")
74+
ChatModelInputObservationHandler armsChatModelInputObservationHandler(ArmsCommonProperties properties) {
75+
return new ChatModelInputObservationHandler(properties.getModel().getMessageMode());
76+
}
77+
78+
@Bean
79+
@ConditionalOnMissingBean(value = { ChatModelOutputObservationHandler.class },
80+
name = { "chatModelOutputObservationHandler" })
81+
@ConditionalOnProperty(prefix = ArmsCommonProperties.CONFIG_PREFIX, name = "model.capture-output",
82+
havingValue = "true")
83+
ChatModelOutputObservationHandler armsChatModelOutputObservationHandler(ArmsCommonProperties properties) {
84+
return new ChatModelOutputObservationHandler(properties.getModel().getMessageMode());
85+
}
86+
4887
}

auto-configurations/spring-ai-alibaba-autoconfigure-arms-observation/src/main/java/com/alibaba/cloud/ai/autoconfigure/arms/ArmsCommonProperties.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.alibaba.cloud.ai.autoconfigure.arms;
1717

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

2021
/**
@@ -33,6 +34,10 @@ public class ArmsCommonProperties {
3334
*/
3435
private boolean enabled = false;
3536

37+
private ModelProperties model = new ModelProperties();
38+
39+
private ToolProperties tool = new ToolProperties();
40+
3641
public boolean isEnabled() {
3742
return enabled;
3843
}
@@ -41,4 +46,77 @@ public void setEnabled(boolean enabled) {
4146
this.enabled = enabled;
4247
}
4348

49+
public ModelProperties getModel() {
50+
return model;
51+
}
52+
53+
public void setModel(ModelProperties model) {
54+
this.model = model;
55+
}
56+
57+
public ToolProperties getTool() {
58+
return tool;
59+
}
60+
61+
public void setTool(ToolProperties tool) {
62+
this.tool = tool;
63+
}
64+
65+
public static class ModelProperties {
66+
67+
/**
68+
* Enable Arms instrumentations and conventions.
69+
*/
70+
private boolean captureInput = false;
71+
72+
/**
73+
* Enable Arms instrumentations and conventions.
74+
*/
75+
private boolean captureOutput = false;
76+
77+
/**
78+
* Arms export type enumeration.
79+
*/
80+
private MessageMode messageMode = MessageMode.OPEN_TELEMETRY;
81+
82+
public boolean isCaptureInput() {
83+
return captureInput;
84+
}
85+
86+
public void setCaptureInput(boolean captureInput) {
87+
this.captureInput = captureInput;
88+
}
89+
90+
public boolean isCaptureOutput() {
91+
return captureOutput;
92+
}
93+
94+
public void setCaptureOutput(boolean captureOutput) {
95+
this.captureOutput = captureOutput;
96+
}
97+
98+
public MessageMode getMessageMode() {
99+
return messageMode;
100+
}
101+
102+
public void setMessageMode(MessageMode messageMode) {
103+
this.messageMode = messageMode;
104+
}
105+
106+
}
107+
108+
public static class ToolProperties {
109+
110+
private boolean enabled = true;
111+
112+
public boolean isEnabled() {
113+
return enabled;
114+
}
115+
116+
public void setEnabled(boolean enabled) {
117+
this.enabled = enabled;
118+
}
119+
120+
}
121+
44122
}

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
<module>spring-ai-alibaba-deepresearch</module>
6262
<module>spring-ai-alibaba-agent-nacos</module>
6363

64+
<!-- Spring AI Alibaba Extension Modules -->
65+
<module>spring-ai-alibaba-observation-extension</module>
66+
6467
<!-- Spring AI Alibaba Tool Call Plugins -->
6568
<module>community/tool-calls/spring-ai-alibaba-starter-tool-calling-common</module>
6669
<module>community/tool-calls/spring-ai-alibaba-starter-tool-calling-time</module>

spring-ai-alibaba-core/src/main/java/com/alibaba/cloud/ai/tool/observation/ArmsToolCallingObservationConvention.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ protected KeyValues toolDescription(KeyValues keyValues, ArmsToolCallingObservat
105105

106106
protected KeyValues toolParameters(KeyValues keyValues, ArmsToolCallingObservationContext context) {
107107
if (context.getToolCall().arguments() != null) {
108-
return keyValues.and(HighCardinalityKeyNames.TOOL_PARAMETERS.asString(), context.getToolCall().arguments());
108+
return keyValues.and(HighCardinalityKeyNames.TOOL_PARAMETERS.asString(), context.getToolCall().arguments())
109+
.and(HighCardinalityKeyNames.INPUT_VALUE.asString(), context.getToolCall().arguments());
109110
}
110111
return keyValues;
111112
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2024-2025 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<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">
18+
<modelVersion>4.0.0</modelVersion>
19+
<parent>
20+
<groupId>com.alibaba.cloud.ai</groupId>
21+
<artifactId>spring-ai-alibaba</artifactId>
22+
<version>${revision}</version>
23+
<relativePath>../pom.xml</relativePath>
24+
</parent>
25+
<artifactId>spring-ai-alibaba-observation-extension</artifactId>
26+
<version>${revision}</version>
27+
<packaging>jar</packaging>
28+
<name>Spring AI Alibaba Observation Extension</name>
29+
<description>Spring AI Alibaba Observation Extension Module, ARMS Implementation</description>
30+
31+
<url>https://github.com/alibaba/spring-ai-alibaba</url>
32+
33+
<scm>
34+
<connection>git://github.com/alibaba/spring-ai-alibaba.git</connection>
35+
<developerConnection>git@github.com:alibaba/spring-ai-alibaba.git</developerConnection>
36+
<url>https://github.com/alibaba/spring-ai-alibaba</url>
37+
</scm>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.ai</groupId>
42+
<artifactId>spring-ai-model</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.ai</groupId>
47+
<artifactId>spring-ai-client-chat</artifactId>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.springframework.ai</groupId>
52+
<artifactId>spring-ai-commons</artifactId>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>io.micrometer</groupId>
57+
<artifactId>micrometer-tracing</artifactId>
58+
<optional>true</optional>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>io.micrometer</groupId>
63+
<artifactId>micrometer-tracing-bridge-otel</artifactId>
64+
<optional>true</optional>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>io.micrometer</groupId>
69+
<artifactId>micrometer-observation-test</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-test</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
</dependencies>
79+
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.springframework.boot</groupId>
84+
<artifactId>spring-boot-maven-plugin</artifactId>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
89+
</project>

0 commit comments

Comments
 (0)