【问题标题】:What is the Recommended Twisted Sentry/Raven Integration?推荐的 Twisted Sentry/Raven 集成是什么?
【发布时间】:2013-10-04 07:31:17
【问题描述】:

raven 有很多集成,包括 python 日志记录。一方面,twisted 不使用 python 的日志记录。另一方面,raven 在twisted 中没有直接集成。

那么,目前在基于扭曲的设置中使用 raven 的最佳做法是什么?

【问题讨论】:

  • 添加为评论而不是答案,因为我从未直接使用过 Sentry / Raven,所以我不知道这是否有帮助。但是,Twisted 支持 Python 标准库日志记录。你看过twistedmatrix.com/documents/13.1.0/api/… 的文档吗?
  • @Glyph:这可能是答案的一部分。首先将日志路由到 python,然后从那里路由到 raven。对我来说,这感觉像是一种解决方法,这就是为什么我要求当前的最佳做法。
  • 短语“最佳实践”意味着每个人都在做一件事,并且有一种公认的正确方法来做这件事,这是某些(可能是官方的)知识体系的一部分。由于似乎很少有人将 Sentry 和 Raven 与 Twisted 一起使用,因此可能有一些方法可以让它发挥作用,但它们都不会成为“最佳实践”。

标签: twisted sentry raven


【解决方案1】:

ravencaptureException 只能在有异常活动的情况下不带参数地调用,这在调用日志观察器时并非总是如此。因此,请从记录的Failure 中提取异常信息:

from twisted.python import log
from raven import Client


client = Client(dsn='twisted+http://YOUR_DSN_HERE')

def logToSentry(event):
    if not event.get('isError') or 'failure' not in event:
        return

    f = event['failure']
    client.captureException((f.type, f.value, f.getTracebackObject()))

log.addObserver(logToSentry)

【讨论】:

  • 1. t.value 中的t 来自哪里? 2.在没有错误的情况下,在return之前做client.captureMessage(event)怎么样?
  • @Elrond,哎呀,应该是f.value。当然,如果你愿意,你可以captureMessage
【解决方案2】:

user1252307 的回答是一个很好的开始,但在哨兵方面,您会得到一个相对无用的字典并且没有堆栈跟踪。

如果您尝试查看和追踪意外异常,请尝试对 log_sentry 函数进行以下小改动:

from twisted.python import log
from raven import Client

client = Client(dsn='twisted+http://YOUR_DSN_HERE')

def log_sentry(dictionary):
    if dictionary.get('isError'):
        if 'failure' in dictionary:
            client.captureException() # Send the current exception info to Sentry.
        else:
            #format the dictionary in whatever way you want
            client.captureMessage(dictionary)

log.addObserver(log_sentry)

也许有更好的方法来过滤基于非异常的错误消息,这可能会尝试发出不存在的异常信息,其中存在非异常的故障。

【讨论】:

  • 这在大多数情况下是不够的,因为在调用日志观察器时通常没有当前异常。
【解决方案3】:
from twisted.python import log
from raven import Client

client = Client(dsn='twisted+http://YOUR_DSN_HERE')

def log_sentry(dictionary):
    if dictionary.get('isError'):
        #format the dictionary in whatever way you want
        client.captureMessage(dictionary)

log.addObserver(log_sentry)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    相关资源
    最近更新 更多