[ 
https://issues.apache.org/jira/browse/CAMEL-12656?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16564968#comment-16564968
 ] 

ASF GitHub Bot commented on CAMEL-12656:
----------------------------------------

davsclaus closed pull request #2448: CAMEL-12656: Fixed root span id for 
multiple routes.
URL: https://github.com/apache/camel/pull/2448
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
 
b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
index fa6d8d2101f..401b14d9e09 100644
--- 
a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
+++ 
b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java
@@ -757,24 +757,16 @@ public void onExchangeBegin(Route route, Exchange 
exchange) {
                     serverRequest(brave, serviceName, exchange);
                 }
             }
+        }
 
-            // add on completion after the route is done, but before the 
consumer writes the response
-            // this allows us to track the zipkin event before returning the 
response which is the right time
-            exchange.addOnCompletion(new SynchronizationAdapter() {
-                @Override
-                public void onAfterRoute(Route route, Exchange exchange) {
-                    String serviceName = getServiceName(exchange, 
route.getEndpoint(), true, false);
-                    Brave brave = getBrave(serviceName);
-                    if (brave != null) {
-                        serverResponse(brave, serviceName, exchange);
-                    }
-                }
-
-                @Override
-                public String toString() {
-                    return "ZipkinTracerOnCompletion[" + routeId + "]";
-                }
-            });
+        // Report Server send after route has completed processing of the 
exchange.
+        @Override
+        public void onExchangeDone(Route route, Exchange exchange) {
+            String serviceName = getServiceName(exchange, route.getEndpoint(), 
true, false);
+            Brave brave = getBrave(serviceName);
+            if (brave != null) {
+                serverResponse(brave, serviceName, exchange);
+            }
         }
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> camel-zipkin - Root Span Id is not reported if the route calls multiple route
> -----------------------------------------------------------------------------
>
>                 Key: CAMEL-12656
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12656
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-zipkin
>    Affects Versions: 2.21.1
>            Reporter: Sourabh Taletiya
>            Priority: Major
>             Fix For: 2.21.3, 2.22.1, 2.23.0
>
>         Attachments: Traces breaking.png, Traces fixed 1.png, Traces fixed 
> 2.png
>
>
> Camel-Zipkin does not report traces with root span id when there are multiple 
> routes. 
> For example: 
>  
> {code:java}
> from("direct:foo")
>         .delay(1000)
>         .to("direct:bar")
>         .to("direct:moo")
>         .to("direct:tar");
> from("direct:bar")
>         .delay(2000);
> from("direct:moo")
>         .delay(1000);
> from("direct:tar")
>         .delay(3000);
> {code}
> Root SpanId(TraceId) should be for service-name = direct:foo and the trace in 
> UI should show all the 4 routes in one sequence. But it breaks. Check the 
> attached screenshot: Traces Breaking.png
> I looked into the code and figured out why its happening. Here is the code 
> which is breaking the functionality.
> Class Name: ZipkinTracer.ZipkinRoutePolicy
> Inside onExchangeBegin() method 
>  
> {code:java}
> // add on completion after the route is done, but before the consumer writes 
> the response
> // this allows us to track the zipkin event before returning the response 
> which is the right time
> exchange.addOnCompletion(new SynchronizationAdapter() {
>     @Override
>     public void onAfterRoute(Route route, Exchange exchange) {
>         String serviceName = getServiceName(exchange, route.getEndpoint(), 
> true, false);
>         Brave brave = getBrave(serviceName);
>         if (brave != null) {
>             serverResponse(brave, serviceName, exchange);
>         }
>     }
>     @Override
>     public String toString() {
>         return "ZipkinTracerOnCompletion[" + routeId + "]";
>     }
> });
> {code}
>  
>  
> Using onAfterRoute() :  if the exchange is being routed through multiple 
> routes, there will be callbacks for each route.
> I have fix for it: 
> If I use onExchangeDone() instead of above code. The traces are reported 
> properly.  Check screenshots.
> [https://zipkin.io/pages/instrumenting.html]
> *Note* This process must be repeated if the service makes multiple downstream 
> calls. That is each subsequent span will have the same trace id and parent 
> id, but a new and different span id.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to