2

I am using Spring Boot 2 Microservices with Spring Cloud Sleuth with the Dependency Management and Spring Cloud Version Greenwich.SR2. My service is running in an Istio service mesh. Sample policy of istio is set to 100 (pilot.traceSampling: 100.0).

To use distributed tracing in the mesh, the applications needs to forward HTTP headers like the X-B3-TraceId and X-B3-SpanID. This is achieved by simply adding Sleuth. All my HTTP request are are traced correctly. The sidecar proxies of Istio (Envoy) send the traces to the Jaeger backend.

Sleuth is also supposed to work with Spring WebSocket. But my incoming websocket requests do not get any trace or span id by sleuth; Logs look like [-,,,]. 1. Question: Why is Sleuth not working for websocket? My WS-Config:

@Configuration
@EnableWebSocket
public class WsConfig implements WebSocketConfigurer {

    @Autowired
    WebSocketHandler webSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

        DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
        handshakeHandler.setSupportedProtocols(HANDSHAKE_PROTOCOL);

        registry.addHandler(webSocketHandler, WS_HANDLER_PATH + WILDCARD)
                .setAllowedOrigins("*")
                .setHandshakeHandler(handshakeHandler);

    }
}

My clients are able to connect to my Service via Websocket. I am implementing WebSocketHandler interface to handle WS messages.

To achieve that my WS connections are logged by Sleuth, I annotate the method that handles my connection with @NewSpan:

    @Override
    @NewSpan
    public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {


        //doWork and call other services via HTTP

    }

With this, Sleuth creates trace and spanId and also propagates them to the other Services, which are called via the restTemplate in this method. But HTTP calls are not send to Jaeger. The x-B3-Sampled Header is always set to 0 by the sidcar. 2 Question: Why are those traces not send to the tracing backend?

Thank you in advance!

nikos
  • 115
  • 7
  • 2
    Update to question 2: It was because you need to set the `spring.sleuth.sampler.percentage` to e.g. 1.0 and use a `ProbabilityBasedSampler` – nikos May 11 '20 at 20:12
  • Hi, can You put Your solution in to an answer and accept it for better visibility for the rest of the community? – Piotr Malec May 12 '20 at 14:20
  • Hi @PiotrMalec, i am still wondering what i mentioned in questions number 1. – nikos May 13 '20 at 16:00
  • Did You configure istio with a installation option to use jaeger? It is point b under ["before you begin"](https://istio.io/docs/tasks/observability/distributed-tracing/jaeger/#before-you-begin) in istio documentation. – Piotr Malec May 19 '20 at 08:29
  • Yes I did. The problem is not that Istio doesnt send the tracing information to Jaeger, I was wondering why Spring Sleuth doesnt start a trace/span for incoming WS connections when using Spring Websocket. Because the incoming WS traffic goes directly to the Spring application and is not processed by the Istio sidecar if I am right. – nikos May 20 '20 at 09:09
  • Yes, I think that might be the case. – Piotr Malec May 22 '20 at 12:02

0 Answers0