Skip to content

Commit eebc451

Browse files
authored
Convert the Redisson lock span into an async span (#667)
1 parent bbb177a commit eebc451

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Release Notes.
1010
* Support for tracing spring-cloud-gateway 4.x in gateway-4.x-plugin.
1111
* Fix re-transform bug when plugin enhanced class proxy parent method.
1212
* Fix error HTTP status codes not recording as SLA failures in Vert.x plugins.
13-
* Support for HttpExchange request tracing
13+
* Support for HttpExchange request tracing.
1414
* Support tracing for async producing, batch sync consuming, and batch async consuming in rocketMQ-client-java-5.x-plugin.
15+
* Convert the Redisson span into an async span.
1516

1617
#### Documentation
1718

apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedissonHighLevelLockInterceptor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2727
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2828
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
29+
import org.redisson.api.RFuture;
2930
import org.redisson.api.RLock;
3031

3132
import java.lang.reflect.Method;
33+
import java.util.concurrent.CompletableFuture;
3234
import java.util.concurrent.TimeUnit;
3335

3436
public class RedissonHighLevelLockInterceptor implements InstanceMethodsAroundInterceptor {
@@ -48,7 +50,19 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4850

4951
@Override
5052
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
53+
AbstractSpan span = ContextManager.activeSpan();
54+
span.prepareForAsync();
5155
ContextManager.stopSpan();
56+
57+
RFuture<Object> future = (RFuture) ret;
58+
CompletableFuture<Object> completableFuture = future.toCompletableFuture();
59+
completableFuture.whenComplete((res, ex) -> {
60+
if (ex != null) {
61+
span.errorOccurred();
62+
span.log(ex);
63+
}
64+
span.asyncFinish();
65+
});
5266
return ret;
5367
}
5468

apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedissonLockInterceptor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2727
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2828
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
29+
import org.redisson.api.RFuture;
2930
import org.redisson.api.RLock;
3031

3132
import java.lang.reflect.Method;
33+
import java.util.concurrent.CompletableFuture;
3234
import java.util.concurrent.TimeUnit;
3335

3436
public class RedissonLockInterceptor implements InstanceMethodsAroundInterceptor {
@@ -48,7 +50,19 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4850

4951
@Override
5052
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
53+
AbstractSpan span = ContextManager.activeSpan();
54+
span.prepareForAsync();
5155
ContextManager.stopSpan();
56+
57+
RFuture<Object> future = (RFuture) ret;
58+
CompletableFuture<Object> completableFuture = future.toCompletableFuture();
59+
completableFuture.whenComplete((res, ex) -> {
60+
if (ex != null) {
61+
span.errorOccurred();
62+
span.log(ex);
63+
}
64+
span.asyncFinish();
65+
});
5266
return ret;
5367
}
5468

0 commit comments

Comments
 (0)