Explanatory comments

This commit is contained in:
David Robertson 2023-04-05 17:54:25 +01:00
parent 32d482edd3
commit 646232dcb0
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
2 changed files with 13 additions and 0 deletions

View File

@ -120,6 +120,9 @@ func main() {
AddPrometheusMetrics: args[EnvPrometheus] != "",
})
// Initialise sentry. We do this in a separate block to the sentry code below,
// because we want to configure logging before starting the pollers—they may want to
// log to sentry themselves.
if args[EnvSentryDsn] != "" {
fmt.Printf("Configuring Sentry reporter...\n")
err := sentry.Init(sentry.ClientOptions{

View File

@ -84,6 +84,16 @@ func (c *Conn) tryRequest(ctx context.Context, req *Request) (res *Response, err
if panicErr != nil {
err = fmt.Errorf("panic: %s", panicErr)
logger.Error().Msg(string(debug.Stack()))
// Note: as we've captured the panicErr ourselves, there isn't much
// difference between RecoverWithContext and CaptureException. But
// there /is/ a small difference:
//
// - RecoverWithContext will generate generate an Sentry event marked with
// a "RecoveredException" hint
// - CaptureException instead uses an "OriginalException" hint.
//
// I'm guessing that Sentry will use the former to display panicErr as
// having come from a panic.
internal.GetSentryHubFromContextOrDefault(ctx).RecoverWithContext(ctx, panicErr)
} else if err != nil {
internal.GetSentryHubFromContextOrDefault(ctx).CaptureException(err)