diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index e0436c60..ab8319bb 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -60,6 +60,7 @@ func MakeAuthAPI( // add the user to Sentry, if enabled hub := sentry.GetHubFromContext(req.Context()) if hub != nil { + hub.Scope().SetTag("username", device.UserID) hub.Scope().SetTag("user_id", device.UserID) hub.Scope().SetTag("device_id", device.ID) } diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index 429cc4bd..a8a3e024 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -188,6 +188,9 @@ func (w *worker) _next() { // Look up what the next event is that's waiting to be processed. ctx, cancel := context.WithTimeout(w.r.ProcessContext.Context(), time.Minute) defer cancel() + if scope := sentry.CurrentHub().Scope(); scope != nil { + scope.SetTag("room_id", w.roomID) + } msgs, err := w.subscription.Fetch(1, nats.Context(ctx)) switch err { case nil: @@ -239,6 +242,9 @@ func (w *worker) _next() { return } + if scope := sentry.CurrentHub().Scope(); scope != nil { + scope.SetTag("event_id", inputRoomEvent.Event.EventID()) + } roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Inc() defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Dec() diff --git a/roomserver/internal/input/input_latest_events.go b/roomserver/internal/input/input_latest_events.go index 7a4105ab..7e42db1b 100644 --- a/roomserver/internal/input/input_latest_events.go +++ b/roomserver/internal/input/input_latest_events.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + "github.com/getsentry/sentry-go" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" "github.com/opentracing/opentracing-go" @@ -284,6 +285,15 @@ func (u *latestEventsUpdater) latestState() error { "old_latest": u.oldLatest.EventIDs(), "new_latest": u.latest.EventIDs(), }).Warnf("State reset detected (removing %d events)", removed) + sentry.WithScope(func(scope *sentry.Scope) { + scope.SetLevel("warning") + scope.SetTag("event_id", u.event.EventID()) + scope.SetTag("old_state_nid", fmt.Sprintf("%d", u.oldStateNID)) + scope.SetTag("new_state_nid", fmt.Sprintf("%d", u.newStateNID)) + scope.SetTag("old_latest", u.oldLatest.EventIDs()) + scope.SetTag("new_latest", u.latest.EventIDs()) + sentry.CaptureMessage("State reset detected") + }) } // Also work out the state before the event removes and the event