【问题标题】:How to log full call-stack with context in raven/sentry?如何在 raven/sentry 中使用上下文记录完整的调用堆栈?
【发布时间】:2016-05-17 08:28:23
【问题描述】:

当在调用堆栈的根部捕获引发的异常时,我可以在 Sentry 中的每个调用堆栈级别看到整个上下文。

但是,当我使用 captureMessage() 时,我在 Sentry 中看不到任何上下文。

如果我在下面的代码中使用 captureException(),我只能看到调用堆栈的顶部。

try:
    raise Exception('Breakpoint!')
except:
    raven_client.captureException()

换句话说,我想在 Sentry 中看到带有完整堆栈跟踪和上下文的记录消息。

【问题讨论】:

    标签: python logging sentry raven


    【解决方案1】:

    Python SDK 能够通过将stack=True 传递给 captureMessage 来捕获任意堆栈跟踪:

    raven_client.captureMessage('hello world', stack=True)
    

    另外还有一个auto_log_stacks值可以在配置客户端时开启:

    raven_client = Client(..., auto_log_stacks=True)
    

    警告:自动记录堆栈很有用,但在某些常见情况下不能保证准确。这也是对性能的影响,尽管是次要的,因为它必须不断地调用inspect.stack()

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 2014-11-13
      • 2014-02-28
      • 2014-01-06
      • 2018-04-24
      • 2013-11-16
      • 2010-11-05
      • 2015-05-29
      • 2011-03-01
      相关资源
      最近更新 更多