What is the recommended integration with twisted clocks / funnels?

There are many integrations for ravens, including python logging. On the one hand, twisted does not use python protocols. And on the other hand, there is no direct integration for a raven in a twisted form.

So what is the best practice of using raven in twisted-tune settings?

+6
source share
3 answers

raven captureException can be captureException only without arguments, if there is an active event, which does not always happen when a log observer is called. So, instead, pull the exception information from Failure that is logged:

 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) 
+8
source

user1252307 The answer is a great start, but on the watchdog side you get a relatively useless dictionary and stack trace.

If you are trying to view and track unexpected exceptions, try this small change in the log_sentry function:

 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) 

There may be a better way to filter the exception-based error message, and this may try to emit exception information that does not exist where there are errors that are not exceptions.

+2
source
 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) 
+1
source

Source: https://habr.com/ru/post/954812/


All Articles