0

We have spring-cloud-starter-sleuth and spring-cloud-starter-zipkin dependencies in in other microservices and we are able to see the traces on the zipkin dashboard. We also want to show the custom messages on zipkin i.e whatever log messages we are logging in our controller methods.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController

public class DemoController {
    @Autowired
    RestTemplate restTemplate;
    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);
    public static final String LOG_FORMAT = "{}: {} ms ";

    @GetMapping(value="demo/demomethod")
    public ResponseEntity<String> getDataFromDemo {
       logger.info(LOG_FORMAT,"Getting Dummy Data From Other Service" ,  System.currentTimeMillis());
        ResponseEntity<String> responseEntity=restTemplate.getForEntity("http://localhost:8290/otherdemo/method2", String.class);
        logger.info(LOG_FORMAT,"Getting Dummy Data From Other Service Ended" ,  System.currentTimeMillis());
        return new ResponseEntity<>("Response returned in Demo Service from Other Service:"+responseEntity.getBody(), HttpStatus.OK);
    }

}

we want to show additional log data on zipkin. Is there any way to show these logger.info messages on the zipkin dashboard? Also, is there any way to customize the format of messages being sent to zipkin? we want to show message in something like %d{yyyy-MMM-dd HH:mm:ss.SSS} %5p [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread] %logger{15} - %replace(%msg %ex){'[\\r\\n]+', '\\n'}%nopex%n format.

implosivesilence
  • 536
  • 10
  • 24
  • Logs are not sent to zipkin. Can you elaborate on what you're trying to achieve – Marcin Grzejszczak Jul 27 '20 at 08:42
  • @Marcin Grzejszczak we want to show additional data on zipkin e.g whatever we're logging under log.info should be visible on the zipkin dashboard as well. If that is not possible, is there any way to format the traces which we are sending to zipkin?we want to show them in the format specified on my question. – implosivesilence Jul 27 '20 at 09:32
  • I don't think it makes any sense really to do it like this but if you need to just annotate the current span via the SpanCustomizer. Then the log you'll put on the span will be visible in Zipkin – Marcin Grzejszczak Jul 27 '20 at 10:00
  • Thanks @Marcin-Grzejszczak. Is there any way to change format of messages being sent to zipkin? – implosivesilence Jul 27 '20 at 10:06
  • I don't understand your question? What format. You're sending JSON messages as bytes to Zipkin where you store all the info about the spans. I'm pretty sure you mix logs with annotations. If you use `log.info` the logged information WILL NOT be sent to Zipkin. – Marcin Grzejszczak Jul 27 '20 at 10:08
  • Thanks @Marcin-Grzejszczak, 'JSON messages as bytes to Zipkin where you store all the info about the spans', is it possible to add any custom data in these messages? Is it possible to change the format of these messages, the way they appear on the zipkin dashboard? – implosivesilence Jul 27 '20 at 10:23
  • No, you can't. I don't understand what you're trying to achieve – Marcin Grzejszczak Jul 27 '20 at 10:24

0 Answers0