From e3555479b4f88436dcf62c9be02db3e5a8c3c42f Mon Sep 17 00:00:00 2001 From: Lemon Date: Sun, 5 May 2019 15:22:13 +0800 Subject: [PATCH] Support RedisTemplate via Jedis Plugin (#2579) * Support byte[] value for Jedis Plugin * When the type of key is byte[], only the method name is recorded. --- .../apm/plugin/jedis/v2/JedisMethodInterceptor.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java index 531804d1f..f154b12a6 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java @@ -20,6 +20,7 @@ package org.apache.skywalking.apm.plugin.jedis.v2; import java.lang.reflect.Method; + import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; @@ -31,7 +32,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt public class JedisMethodInterceptor implements InstanceMethodsAroundInterceptor { - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan("Jedis/" + method.getName(), peer); @@ -41,16 +43,20 @@ public class JedisMethodInterceptor implements InstanceMethodsAroundInterceptor if (allArguments.length > 0 && allArguments[0] instanceof String) { Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); + } else if (allArguments.length > 0 && allArguments[0] instanceof byte[]) { + Tags.DB_STATEMENT.set(span, method.getName()); } } - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { ContextManager.stopSpan(); return ret; } - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Throwable t) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred();