问题
I recently upgraded my project from Spring Boot 1.4.1, Spring Cloud Sleuth 1.1.0, Spring Cloud Zipkin 1.1.0 to Spring Boot 1.5.3, Spring Cloud Sleuth 1.2.0, Spring Cloud Zipkin 1.2.0.
Read that with the latest version of Spring Cloud Sleuth, they had added "error" tags which will get reported to Zipkin automatically in case of any exceptions.
I have a @ControllerAdvice class extending ResponseEntityExceptionHandler for custom exception handling. I was able to report errors to the Tracer and visualize the same in Zipkin when using the old versions (Spring Boot 1.4.1, Spring Cloud Sleuth 1.1.0, Spring Cloud Zipkin 1.1.0) using the below method:
private void reportErrorSpan(String errorDesc, String message) {
if(tracer != null) {
Span span = tracer.getCurrentSpan();
span.logEvent("ERROR: " + message);
tracer.addTag("error", errorDesc);
}
}
After I upgraded, this doesn't seem to work and spring cloud sleuth's default error reporting was also not happening. Only after commenting out the @ControllerAdvice and letting Spring Boot's default ErrorController to handle the exceptions, I was able to visualize the errors in Zipkin. However, we need the custom exception handling to format the error response in a standard way with error codes across all our PaaS services. Is there a way to do this? Should I use any other Sleuth objects to achieve this?
回答1:
The issue got fixed - https://github.com/spring-cloud/spring-cloud-sleuth/issues/585 . In the upcoming releases 1.1.5 and 1.2.1 it should work
来源:https://stackoverflow.com/questions/43790619/sleuth-zipkin-tracing-with-controlleradvice