Correct the duration of the transaction span for Neo4J 4.x (#353)

* Fix https://github.com/apache/skywalking/issues/9800, wait for the end of the transaction to close the span.
This commit is contained in:
Guillaume Alvarez 2022-10-18 15:35:01 +02:00 committed by GitHub
parent 23b3c2d35e
commit bd76d1a618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -16,6 +16,7 @@ Release Notes.
* Update `compose-start-script.template` to make compatible with new version docker compose * Update `compose-start-script.template` to make compatible with new version docker compose
* Bump up grpc to 1.50.0 to fix CVE-2022-3171 * Bump up grpc to 1.50.0 to fix CVE-2022-3171
* Polish up nats plugin to unify MQ related tags * Polish up nats plugin to unify MQ related tags
* Correct the duration of the transaction span for Neo4J 4.x.
#### Documentation #### Documentation

View File

@ -19,6 +19,7 @@
package org.apache.skywalking.apm.plugin.neo4j.v4x; package org.apache.skywalking.apm.plugin.neo4j.v4x;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.CompletionStage;
import org.apache.skywalking.apm.agent.core.context.ContextManager; 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.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
@ -61,13 +62,15 @@ public class TransactionRunInterceptor implements InstanceMethodsAroundIntercept
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
SessionRequiredInfo requiredInfo = (SessionRequiredInfo) objInst.getSkyWalkingDynamicField(); return ((CompletionStage<?>) ret).thenApply(resultCursor -> {
if (requiredInfo == null || requiredInfo.getSpan() == null) { SessionRequiredInfo requiredInfo = (SessionRequiredInfo) objInst.getSkyWalkingDynamicField();
return ret; if (requiredInfo == null || requiredInfo.getSpan() == null) {
} return resultCursor;
}
requiredInfo.getSpan().asyncFinish(); requiredInfo.getSpan().asyncFinish();
return ret; return resultCursor;
});
} }
@Override @Override