简体   繁体   English

使用Opentracing和Jaeger记录异常

[英]Logging Exceptions with Opentracing and Jaeger

I've set up Jaeger with Opentracing in a Java environment and it works nicely with logging messages with spans and tracing. 我在Java环境中使用Opentracing设置了Jaeger,它非常适合与跨度和跟踪记录消息一起使用。 But I am a bit stuck when it comes to catching and logging exceptions. 但是,在捕获和记录异常方面我有些困惑。

    try
    {
        span.log(ImmutableMap.of("Exeption", "ex"));
        throw new IllegalArgumentException("Expecting one argument");
    }
    catch(Exception ex)
    {
       span.log(ImmutableMap.of("Error", ex));
       span.log(ImmutableMap.of("Event", "error", "Error-object", ex, "message", ex.getStackTrace()));
    }

But this way does not format error logging in a good readable way. 但是这种方式不能以一种易于阅读的方式格式化错误日志。

I have looked around for information about this as it feels pretty obvious there should be as this is one of its components for logging. 我四处寻找有关此问题的信息,因为它显然是应该记录的组成部分之一,应该感觉很明显。 But I have somehow never seen anything about this. 但是我以某种方式从未见过任何东西。 It is mostly about building and structuring spans. 它主要是关于跨度的构建和构造。 Hope anyone can help me with this when it comes to capturing and logging exceptions. 希望在捕获和记录异常方面有人可以帮助我。

This issue looks more to have to do with Java it self then either Opentracing and Jaeger. 这个问题看起来更多与Java本身有关,然后与Opentracing和Jaeger有关。 as ex.getStackTrace() is more of the problem. 因为ex.getStackTrace()是更多的问题。 As it should be more like 因为它应该更像

StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
span.setTag("error", true);
span.log(ImmutableMap.of("stack", errors));

Problem solved. 问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM