This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 01248a2063 Fix problem which lead redisson plugin to throw unnecessary 
NullPointerException (#700)
01248a2063 is described below

commit 01248a20632f95e4cb6a8eec08b22b814e058319
Author: Ricehomesky <63052374+ricehome...@users.noreply.github.com>
AuthorDate: Mon Jun 24 08:48:15 2024 +0800

    Fix problem which lead redisson plugin to throw unnecessary 
NullPointerException (#700)
---
 .../v3/RedisConnectionMethodInterceptor.java       | 29 +++++++++++++---------
 .../v3/define/RedisConnectionInstrumentation.java  | 14 +++++------
 2 files changed, 24 insertions(+), 19 deletions(-)

diff --git 
a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java
 
b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java
index f660ca1a15..d475382c8f 100644
--- 
a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java
+++ 
b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java
@@ -19,6 +19,8 @@
 package org.apache.skywalking.apm.plugin.redisson.v3;
 
 import io.netty.channel.Channel;
+
+import java.util.Objects;
 import java.util.stream.Collectors;
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.context.tag.Tags;
@@ -28,8 +30,8 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog;
 import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext;
 import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
 import org.apache.skywalking.apm.plugin.redisson.v3.util.ClassUtil;
 import org.apache.skywalking.apm.util.StringUtil;
@@ -42,17 +44,17 @@ import java.lang.reflect.Method;
 import java.net.InetSocketAddress;
 import java.util.Optional;
 
-public class RedisConnectionMethodInterceptor implements 
InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor {
+public class RedisConnectionMethodInterceptor implements 
InstanceMethodsAroundInterceptorV2, InstanceConstructorInterceptor {
 
     private static final ILog LOGGER = 
LogManager.getLogger(RedisConnectionMethodInterceptor.class);
 
     private static final String ABBR = "...";
     private static final String QUESTION_MARK = "?";
     private static final String DELIMITER_SPACE = " ";
+    public static final Object STOP_SPAN_FLAG = new Object();
 
     @Override
-    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes,
-        MethodInterceptResult result) throws Throwable {
+    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) 
throws Throwable {
         String peer = (String) objInst.getSkyWalkingDynamicField();
 
         RedisConnection connection = (RedisConnection) objInst;
@@ -82,6 +84,7 @@ public class RedisConnectionMethodInterceptor implements 
InstanceMethodsAroundIn
         }
 
         AbstractSpan span = ContextManager.createExitSpan(operationName, peer);
+        context.setContext(STOP_SPAN_FLAG);
         span.setComponent(ComponentsDefine.REDISSON);
         Tags.CACHE_TYPE.set(span, "Redis");
         Tags.CACHE_INSTANCE.set(span, dbInstance);
@@ -93,17 +96,19 @@ public class RedisConnectionMethodInterceptor implements 
InstanceMethodsAroundIn
     }
 
     @Override
-    public Object afterMethod(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes,
-        Object ret) throws Throwable {
-        ContextManager.stopSpan();
+    public Object afterMethod(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes, Object ret, 
MethodInvocationContext context) throws Throwable {
+        if (Objects.nonNull(context.getContext())) {
+            ContextManager.stopSpan();
+        }
         return ret;
     }
 
     @Override
-    public void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments,
-        Class<?>[] argumentsTypes, Throwable t) {
-        AbstractSpan span = ContextManager.activeSpan();
-        span.log(t);
+    public void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes, Throwable t, 
MethodInvocationContext context) {
+        if (Objects.nonNull(context.getContext())) {
+            AbstractSpan span = ContextManager.activeSpan();
+            span.log(t);
+        }
     }
 
     @Override
diff --git 
a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java
 
b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java
index 84bc82535f..34678af6b7 100644
--- 
a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java
+++ 
b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java
@@ -21,15 +21,15 @@ package org.apache.skywalking.apm.plugin.redisson.v3.define;
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
 
 import static net.bytebuddy.matcher.ElementMatchers.named;
 import static 
org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
 import static 
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
 
-public class RedisConnectionInstrumentation extends 
ClassInstanceMethodsEnhancePluginDefine {
+public class RedisConnectionInstrumentation extends 
ClassInstanceMethodsEnhancePluginDefineV2 {
 
     private static final String ENHANCE_CLASS = 
"org.redisson.client.RedisConnection";
 
@@ -53,16 +53,16 @@ public class RedisConnectionInstrumentation extends 
ClassInstanceMethodsEnhanceP
     }
 
     @Override
-    public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() 
{
-        return new InstanceMethodsInterceptPoint[] {
-            new InstanceMethodsInterceptPoint() {
+    public InstanceMethodsInterceptV2Point[] 
getInstanceMethodsInterceptV2Points() {
+        return new InstanceMethodsInterceptV2Point[] {
+            new InstanceMethodsInterceptV2Point() {
                 @Override
                 public ElementMatcher<MethodDescription> getMethodsMatcher() {
                     return named("send");
                 }
 
                 @Override
-                public String getMethodsInterceptor() {
+                public String getMethodsInterceptorV2() {
                     return REDISSON_METHOD_INTERCEPTOR_CLASS;
                 }
 

Reply via email to