From bd76d1a618bdfece06d52201c3daef36bb2a2efb Mon Sep 17 00:00:00 2001 From: Guillaume Alvarez Date: Tue, 18 Oct 2022 15:35:01 +0200 Subject: [PATCH] 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. --- CHANGES.md | 1 + .../neo4j/v4x/TransactionRunInterceptor.java | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1d52e09bc..55bd238db 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Release Notes. * 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 * Polish up nats plugin to unify MQ related tags +* Correct the duration of the transaction span for Neo4J 4.x. #### Documentation diff --git a/apm-sniffer/apm-sdk-plugin/neo4j-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/neo4j/v4x/TransactionRunInterceptor.java b/apm-sniffer/apm-sdk-plugin/neo4j-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/neo4j/v4x/TransactionRunInterceptor.java index 0607f77d4..e4bf10e18 100644 --- a/apm-sniffer/apm-sdk-plugin/neo4j-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/neo4j/v4x/TransactionRunInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/neo4j-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/neo4j/v4x/TransactionRunInterceptor.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.plugin.neo4j.v4x; 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.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -61,13 +62,15 @@ public class TransactionRunInterceptor implements InstanceMethodsAroundIntercept @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { - SessionRequiredInfo requiredInfo = (SessionRequiredInfo) objInst.getSkyWalkingDynamicField(); - if (requiredInfo == null || requiredInfo.getSpan() == null) { - return ret; - } + return ((CompletionStage) ret).thenApply(resultCursor -> { + SessionRequiredInfo requiredInfo = (SessionRequiredInfo) objInst.getSkyWalkingDynamicField(); + if (requiredInfo == null || requiredInfo.getSpan() == null) { + return resultCursor; + } - requiredInfo.getSpan().asyncFinish(); - return ret; + requiredInfo.getSpan().asyncFinish(); + return resultCursor; + }); } @Override