Co-authored-by: forrestwang <forrest.wang@woo.network>
This commit is contained in:
parent
ec30b5f53d
commit
1a01047007
|
|
@ -28,22 +28,11 @@ import java.lang.reflect.Method;
|
|||
public abstract class AbstractThreadingPoolInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
if (!ContextManager.isActive()) {
|
||||
if (notToEnhance(allArguments)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (allArguments == null || allArguments.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object argument = allArguments[0];
|
||||
|
||||
// Avoid duplicate enhancement, such as the case where it has already been enhanced by RunnableWrapper or CallableWrapper with toolkit.
|
||||
if (argument instanceof EnhancedInstance && ((EnhancedInstance) argument).getSkyWalkingDynamicField() instanceof ContextSnapshot) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object wrappedObject = wrap(argument);
|
||||
Object wrappedObject = wrap(allArguments[0]);
|
||||
if (wrappedObject != null) {
|
||||
allArguments[0] = wrappedObject;
|
||||
}
|
||||
|
|
@ -63,10 +52,25 @@ public abstract class AbstractThreadingPoolInterceptor implements InstanceMethod
|
|||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
|
||||
if (!ContextManager.isActive()) {
|
||||
if (notToEnhance(allArguments)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ContextManager.activeSpan().log(t);
|
||||
}
|
||||
|
||||
private boolean notToEnhance(Object[] allArguments) {
|
||||
if (!ContextManager.isActive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (allArguments == null || allArguments.length < 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Object argument = allArguments[0];
|
||||
|
||||
// Avoid duplicate enhancement, such as the case where it has already been enhanced by RunnableWrapper or CallableWrapper with toolkit.
|
||||
return argument instanceof EnhancedInstance && ((EnhancedInstance) argument).getSkyWalkingDynamicField() instanceof ContextSnapshot;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue