I found there is an old issue Sleuth/Zipkin tracing with @ControllerAdvice, but I meet the same problem with the latest version(spring-cloud-starter-zipkin:2.1.0.RELEASE), I debug it and find that the error is null, so zipkin just guess with statuscode. I have to throw the exception again to make zipkin notify the exception
Asked
Active
Viewed 300 times
0
-
Can you create a sample that replicates the problem and upload it to github? – Marcin Grzejszczak Feb 12 '19 at 13:28
-
see https://github.com/fantasyofjay/zipkindemo1, ExceptionHanders, if return string, zipkin just log error as "500 – Jay Fantasy Feb 13 '19 at 12:45
-
hi, Marcin, can you see the demo? – Jay Fantasy Feb 18 '19 at 07:34
1 Answers
0
It makes perfect sense that it's null
. That's because YOU control the way what happens with the caught exception. In your case, nothing, cause you swallow that exception.
If you want to do sth better, just add the error tag manually via the SpanCustomizer
. That way you'll add the exception to the given span. It will then automatically get closed and reported to Zipkin (you can do sth else than ex.toString()
of course.
@Slf4j
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExceptionHanders {
private final SpanCustomizer customizer;
public ExceptionHanders(SpanCustomizer customizer) {
this.customizer = customizer;
}
@ExceptionHandler({RuntimeException.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleRuntimeException(Exception ex) throws Exception {
this.customizer.tag("error", ex.toString());
return "testabcd";
}
}

Marcin Grzejszczak
- 10,624
- 1
- 16
- 32
-
it don't work, ExceptionHanders execute before HttpParser.error, and HttpParser.error function will tag error with maybeErrorStatus again. – Jay Fantasy Apr 11 '19 at 12:30
-
HttpParser.error: if (error != null) { errorParser().error(error, customizer); } else if (httpStatus != null) { String maybeErrorStatus = maybeStatusAsString(httpStatus, 399); if (maybeErrorStatus != null) customizer.tag("error", maybeErrorStatus); } – Jay Fantasy Apr 11 '19 at 12:31
-
I use another tag errorDetails, tks. this.customizer.tag("errorDetail", ex.toString()); – Jay Fantasy Apr 11 '19 at 12:46