sentry-go
sentry-go copied to clipboard
Return panic message from sentry.RecoverWithContext()
Summary
Recover & RecoverWithContext should return the panic message as well as the EventID.
func (ctx context.Context) {
defer func(){
if eventID, err := sentry.RecoverWithContext(ctx); err != nil {
// logs panic message to stdout
logger.For(ctx).Panic(err, zap.String("sentry.event_id", eventID)
}
}()
}
Motivation
sentry.RecoverWithContext() is a really helpful utility function that wraps a lot of standard code I would normally write for recovering from panics in goroutines.
At the moment the panic messages are swallowed by the Recover* methods on the top level sentry package - this makes it very difficult to debug/develop locally. The EventID messages are useful, but the error messages are essential. I always want to log the panic message somewhere as well as sending it to Sentry.
I could use:
localHub := sentry.GetHubFromContext(ctx)
if localHub == nil {
localHub = sentry.GetCurrentHub().Clone()
}
defer func (ctx context.Context) {
if err := recover(); err != nil {
eventIID := localHub.RecoverWithContext(ctx, err)
logger.For(ctx).Panic(err, zap.String("sentry.event_id", eventID))
}
}()
panic("oh no!")
but sentry.RecoverWithContext() is now useless to me.
Additional Context
None!