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;
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue