You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/10/18 13:35:08 UTC

[skywalking-java] branch main updated: Correct the duration of the transaction span for Neo4J 4.x (#353)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new bd76d1a618 Correct the duration of the transaction span for Neo4J 4.x (#353)
bd76d1a618 is described below

commit bd76d1a618bdfece06d52201c3daef36bb2a2efb
Author: Guillaume Alvarez <gu...@users.noreply.github.com>
AuthorDate: Tue Oct 18 15:35:01 2022 +0200

    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 +
 .../apm/plugin/neo4j/v4x/TransactionRunInterceptor.java   | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 1d52e09bcd..55bd238dbd 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 0607f77d49..e4bf10e183 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