Skip to content

Commit f6675da

Browse files
committed
Merge branch 'dev' into uat
# Conflicts: # apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/AbstractObservationVectorStoreConstructorInterceptor.java # apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/define/AbstractObservationVectorStoreInstrumentation.java
2 parents a9843a7 + d772141 commit f6675da

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/AbstractObservationVectorStoreConstructorInterceptor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2222
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
2323
import org.springframework.ai.embedding.EmbeddingOptions;
24+
import org.springframework.ai.embedding.EmbeddingModel;
2425
import org.springframework.util.StringUtils;
2526

2627
import java.lang.reflect.Field;
@@ -31,11 +32,18 @@ public class AbstractObservationVectorStoreConstructorInterceptor implements Ins
3132
@Override
3233
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
3334
if (allArguments != null && allArguments.length > 0) {
34-
String embeddingModelName = resolveModelFromEmbeddingModel(allArguments[0]);
35+
String embeddingModelName = resolveModelFromArgument(allArguments[0]);
3536
objInst.setSkyWalkingDynamicField(new VectorStoreEnhanceContext(embeddingModelName));
3637
}
3738
}
3839

40+
private String resolveModelFromArgument(Object argument) {
41+
if (argument instanceof EmbeddingModel) {
42+
return resolveModelFromEmbeddingModel(argument);
43+
}
44+
return null;
45+
}
46+
3947
private String resolveModelFromEmbeddingModel(Object embeddingModel) {
4048
if (embeddingModel == null) {
4149
return null;

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/define/AbstractObservationVectorStoreInstrumentation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2626
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2727
import org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch;
28+
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
29+
import org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalMatchOperation;
2830

2931
import static net.bytebuddy.matcher.ElementMatchers.named;
3032
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -34,8 +36,6 @@ public class AbstractObservationVectorStoreInstrumentation extends ClassInstance
3436

3537
private static final String ENHANCE_CLASS = "org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore";
3638

37-
private static final String EMBEDDING_MODEL_CLASS = "org.springframework.ai.embedding.EmbeddingModel";
38-
3939
private static final String INTERCEPT_METHOD = "doSimilaritySearch";
4040

4141
private static final String INTERCEPTOR_CLASS =
@@ -46,16 +46,16 @@ public class AbstractObservationVectorStoreInstrumentation extends ClassInstance
4646

4747
@Override
4848
protected ClassMatch enhanceClass() {
49-
return HierarchyMatch.byHierarchyMatch(ENHANCE_CLASS);
49+
return LogicalMatchOperation.or(HierarchyMatch.byHierarchyMatch(ENHANCE_CLASS), MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS));
5050
}
5151

5252
@Override
5353
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
54-
return new ConstructorInterceptPoint[] {
54+
return new ConstructorInterceptPoint[]{
5555
new ConstructorInterceptPoint() {
5656
@Override
5757
public ElementMatcher<MethodDescription> getConstructorMatcher() {
58-
return takesArguments(4).and(takesArgumentWithType(0, EMBEDDING_MODEL_CLASS));
58+
return takesArgumentWithType(0, "org.springframework.ai.embedding.EmbeddingModel");
5959
}
6060

6161
@Override
@@ -68,7 +68,7 @@ public String getConstructorInterceptor() {
6868

6969
@Override
7070
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
71-
return new InstanceMethodsInterceptPoint[] {
71+
return new InstanceMethodsInterceptPoint[]{
7272
new InstanceMethodsInterceptPoint() {
7373
@Override
7474
public ElementMatcher<MethodDescription> getMethodsMatcher() {

0 commit comments

Comments
 (0)