You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/09/02 02:22:04 UTC
[GitHub] [skywalking-java] darcydai commented on a change in pull request #17: optimize lettuce plugin
darcydai commented on a change in pull request #17:
URL: https://github.com/apache/skywalking-java/pull/17#discussion_r700694981
##########
File path: apm-sniffer/apm-sdk-plugin/lettuce-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/lettuce/v5/RedisCommandCancelMethodInterceptor.java
##########
@@ -18,49 +18,39 @@
package org.apache.skywalking.apm.plugin.lettuce.v5;
-import io.lettuce.core.protocol.AsyncCommand;
-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.trace.AbstractSpan;
-import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
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.network.trace.component.ComponentsDefine;
import java.lang.reflect.Method;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-public class AsyncCommandMethodInterceptor implements InstanceMethodsAroundInterceptor {
+public class RedisCommandCancelMethodInterceptor implements InstanceMethodsAroundInterceptor {
+ private static final String COMMAND_CANCEL_VALUE = "cancel";
@Override
- @SuppressWarnings("unchecked")
- public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
- MethodInterceptResult result) throws Throwable {
- AsyncCommand asyncCommand = (AsyncCommand) objInst;
- String operationName = "Lettuce/" + asyncCommand.getType().name();
- AbstractSpan span = ContextManager.createLocalSpan(operationName + "/onComplete");
- span.setComponent(ComponentsDefine.LETTUCE);
- Tags.DB_TYPE.set(span, "Redis");
- SpanLayer.asCache(span);
- if (allArguments[0] instanceof Consumer) {
- allArguments[0] = new SWConsumer((Consumer) allArguments[0], ContextManager.capture(), operationName);
- } else {
- allArguments[0] = new SWBiConsumer((BiConsumer) allArguments[0], ContextManager.capture(), operationName);
- }
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) {
}
@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) {
+ if (objInst.getSkyWalkingDynamicField() != null) {
+ AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField();
+ span.errorOccurred();
+ Tags.SIGNAL_TYPE.set(span, COMMAND_CANCEL_VALUE);
+ span.asyncFinish();
+ //help gc
+ objInst.setSkyWalkingDynamicField(null);
Review comment:
yes, 'set null' another usage is prevented async finish repeatedly. this 'objInst' is Redis Command will return to Redis user, 'set null' can let Redis Command not refer to span after it finished
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org