'Zipkin upstream span ended before downstream span

I have Gateway (Spring Cloud Gateway) and API services (Spring Boot) running on localhost. The API service is behind the Gateway. The Gateway service will route all /api/** endpoints to the API service. I have Sleuth and Zipkin set up too. It is all working fine but I'm not able to understand why Zipkin is showing the following trace. Showing here is a simple GET request to endpoint /api/ping. The question is why the Gateway span ends before API span? Shouldn't it be other way around? What is the logic behind this?

enter image description here

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source