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.