Fix problem which lead redisson plugin to throw unnecessary NullPointerException (#700)
This commit is contained in:
parent
8200cf2b51
commit
01248a2063
|
|
@ -19,6 +19,8 @@
|
||||||
package org.apache.skywalking.apm.plugin.redisson.v3;
|
package org.apache.skywalking.apm.plugin.redisson.v3;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||||
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
|
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.logging.api.LogManager;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
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.InstanceConstructorInterceptor;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
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.network.trace.component.ComponentsDefine;
|
||||||
import org.apache.skywalking.apm.plugin.redisson.v3.util.ClassUtil;
|
import org.apache.skywalking.apm.plugin.redisson.v3.util.ClassUtil;
|
||||||
import org.apache.skywalking.apm.util.StringUtil;
|
import org.apache.skywalking.apm.util.StringUtil;
|
||||||
|
|
@ -42,17 +44,17 @@ import java.lang.reflect.Method;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Optional;
|
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 ILog LOGGER = LogManager.getLogger(RedisConnectionMethodInterceptor.class);
|
||||||
|
|
||||||
private static final String ABBR = "...";
|
private static final String ABBR = "...";
|
||||||
private static final String QUESTION_MARK = "?";
|
private static final String QUESTION_MARK = "?";
|
||||||
private static final String DELIMITER_SPACE = " ";
|
private static final String DELIMITER_SPACE = " ";
|
||||||
|
public static final Object STOP_SPAN_FLAG = new Object();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) throws Throwable {
|
||||||
MethodInterceptResult result) throws Throwable {
|
|
||||||
String peer = (String) objInst.getSkyWalkingDynamicField();
|
String peer = (String) objInst.getSkyWalkingDynamicField();
|
||||||
|
|
||||||
RedisConnection connection = (RedisConnection) objInst;
|
RedisConnection connection = (RedisConnection) objInst;
|
||||||
|
|
@ -82,6 +84,7 @@ public class RedisConnectionMethodInterceptor implements InstanceMethodsAroundIn
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractSpan span = ContextManager.createExitSpan(operationName, peer);
|
AbstractSpan span = ContextManager.createExitSpan(operationName, peer);
|
||||||
|
context.setContext(STOP_SPAN_FLAG);
|
||||||
span.setComponent(ComponentsDefine.REDISSON);
|
span.setComponent(ComponentsDefine.REDISSON);
|
||||||
Tags.CACHE_TYPE.set(span, "Redis");
|
Tags.CACHE_TYPE.set(span, "Redis");
|
||||||
Tags.CACHE_INSTANCE.set(span, dbInstance);
|
Tags.CACHE_INSTANCE.set(span, dbInstance);
|
||||||
|
|
@ -93,18 +96,20 @@ public class RedisConnectionMethodInterceptor implements InstanceMethodsAroundIn
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret, MethodInvocationContext context) throws Throwable {
|
||||||
Object ret) throws Throwable {
|
if (Objects.nonNull(context.getContext())) {
|
||||||
ContextManager.stopSpan();
|
ContextManager.stopSpan();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) {
|
||||||
Class<?>[] argumentsTypes, Throwable t) {
|
if (Objects.nonNull(context.getContext())) {
|
||||||
AbstractSpan span = ContextManager.activeSpan();
|
AbstractSpan span = ContextManager.activeSpan();
|
||||||
span.log(t);
|
span.log(t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,15 @@ package org.apache.skywalking.apm.plugin.redisson.v3.define;
|
||||||
import net.bytebuddy.description.method.MethodDescription;
|
import net.bytebuddy.description.method.MethodDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
|
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.v2.ClassInstanceMethodsEnhancePluginDefineV2;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||||
|
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
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.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
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";
|
private static final String ENHANCE_CLASS = "org.redisson.client.RedisConnection";
|
||||||
|
|
||||||
|
|
@ -53,16 +53,16 @@ public class RedisConnectionInstrumentation extends ClassInstanceMethodsEnhanceP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() {
|
||||||
return new InstanceMethodsInterceptPoint[] {
|
return new InstanceMethodsInterceptV2Point[] {
|
||||||
new InstanceMethodsInterceptPoint() {
|
new InstanceMethodsInterceptV2Point() {
|
||||||
@Override
|
@Override
|
||||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||||
return named("send");
|
return named("send");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMethodsInterceptor() {
|
public String getMethodsInterceptorV2() {
|
||||||
return REDISSON_METHOD_INTERCEPTOR_CLASS;
|
return REDISSON_METHOD_INTERCEPTOR_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue