Convert the Redisson lock span into an async span (#667)

This commit is contained in:
peachisai 2024-01-21 12:10:39 +08:00 committed by GitHub
parent bbb177a893
commit eebc4512ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 1 deletions

View File

@ -10,8 +10,9 @@ Release Notes.
* Support for tracing spring-cloud-gateway 4.x in gateway-4.x-plugin.
* Fix re-transform bug when plugin enhanced class proxy parent method.
* Fix error HTTP status codes not recording as SLA failures in Vert.x plugins.
* Support for HttpExchange request tracing
* Support for HttpExchange request tracing.
* Support tracing for async producing, batch sync consuming, and batch async consuming in rocketMQ-client-java-5.x-plugin.
* Convert the Redisson span into an async span.
#### Documentation

View File

@ -26,9 +26,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI
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 org.redisson.api.RFuture;
import org.redisson.api.RLock;
import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
public class RedissonHighLevelLockInterceptor implements InstanceMethodsAroundInterceptor {
@ -48,7 +50,19 @@ public class RedissonHighLevelLockInterceptor implements InstanceMethodsAroundIn
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
AbstractSpan span = ContextManager.activeSpan();
span.prepareForAsync();
ContextManager.stopSpan();
RFuture<Object> future = (RFuture) ret;
CompletableFuture<Object> completableFuture = future.toCompletableFuture();
completableFuture.whenComplete((res, ex) -> {
if (ex != null) {
span.errorOccurred();
span.log(ex);
}
span.asyncFinish();
});
return ret;
}

View File

@ -26,9 +26,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI
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 org.redisson.api.RFuture;
import org.redisson.api.RLock;
import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
public class RedissonLockInterceptor implements InstanceMethodsAroundInterceptor {
@ -48,7 +50,19 @@ public class RedissonLockInterceptor implements InstanceMethodsAroundInterceptor
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
AbstractSpan span = ContextManager.activeSpan();
span.prepareForAsync();
ContextManager.stopSpan();
RFuture<Object> future = (RFuture) ret;
CompletableFuture<Object> completableFuture = future.toCompletableFuture();
completableFuture.whenComplete((res, ex) -> {
if (ex != null) {
span.errorOccurred();
span.log(ex);
}
span.asyncFinish();
});
return ret;
}