mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-02-01 22:47:40 +00:00
fix(events): report async errors via Sentry
This commit is contained in:
@@ -19,6 +19,8 @@ package events
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"time"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
@@ -38,6 +40,14 @@ type Event interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
type messageHandleFailedError struct {
|
||||
Metadata message.Metadata
|
||||
}
|
||||
|
||||
func (m *messageHandleFailedError) Error() string {
|
||||
return fmt.Sprintf("Failed to handle message: %v", m.Metadata)
|
||||
}
|
||||
|
||||
// InitEvents sets up everything needed to work with events
|
||||
func InitEvents() (err error) {
|
||||
logger := log.NewWatermillLogger(config.LogEnabled.GetBool(), config.LogEvents.GetString(), config.LogEventsLevel.GetString())
|
||||
@@ -70,6 +80,12 @@ func InitEvents() (err error) {
|
||||
meta += s + "=" + m + ", "
|
||||
}
|
||||
log.Errorf("Error while handling message %s, %s payload=%s", msg.UUID, meta, string(msg.Payload))
|
||||
|
||||
if config.SentryEnabled.GetBool() {
|
||||
sentry.CaptureException(&messageHandleFailedError{
|
||||
Metadata: msg.Metadata,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user