Skip to content

Commit

Permalink
Merge pull request #9 from peachisai/dev
Browse files Browse the repository at this point in the history
Convert the redisson lock into a async span
  • Loading branch information
peachisai authored Jan 20, 2024
2 parents d5b99f9 + 2bc2676 commit a6c5d8c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Release Notes.
* 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
* Convert the Redisson lock span into an async span

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
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 {
Expand All @@ -48,7 +50,19 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr

@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.whenCompleteAsync((res, ex) -> {
if (ex != null) {
span.errorOccurred();
span.log(ex);
}
span.asyncFinish();
});
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
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 {
Expand All @@ -48,7 +50,19 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr

@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.whenCompleteAsync((res, ex) -> {
if (ex != null) {
span.errorOccurred();
span.log(ex);
}
span.asyncFinish();
});
return ret;
}

Expand Down

0 comments on commit a6c5d8c

Please sign in to comment.