0

我发现有一个老问题Sleuth/Zipkin tracking with @ControllerAdvice,但是我在最新版本(spring-cloud-starter-zipkin:2.1.0.RELEASE)遇到了同样的问题,我调试它并发现错误是null,所以 zipkin 只是猜测状态码。我必须再次抛出异常以使 zipkin 通知异常

错误为空

拉链结果

控制器建议

再次抛出异常,它的工作原理

4

1 回答 1

0

这是完全有道理的null。那是因为您控制捕获的异常发生的方式。在你的情况下,没有什么,因为你吞下了那个异常。

如果您想做得更好,只需通过SpanCustomizer. 这样您就可以将异常添加到给定的跨度中。然后它会自动关闭并报告给 Zipkin(你ex.toString()当然可以做其他事情。

@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";
    }
}
于 2019-02-19T12:25:08.080 回答