Improve Sentry reporting

This commit is contained in:
Neil Alexander 2022-09-05 17:25:11 +01:00
parent ecee5f10f4
commit cd22ba22b0
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 17 additions and 0 deletions

View file

@ -60,6 +60,7 @@ func MakeAuthAPI(
// add the user to Sentry, if enabled // add the user to Sentry, if enabled
hub := sentry.GetHubFromContext(req.Context()) hub := sentry.GetHubFromContext(req.Context())
if hub != nil { if hub != nil {
hub.Scope().SetTag("username", device.UserID)
hub.Scope().SetTag("user_id", device.UserID) hub.Scope().SetTag("user_id", device.UserID)
hub.Scope().SetTag("device_id", device.ID) hub.Scope().SetTag("device_id", device.ID)
} }

View file

@ -188,6 +188,9 @@ func (w *worker) _next() {
// Look up what the next event is that's waiting to be processed. // Look up what the next event is that's waiting to be processed.
ctx, cancel := context.WithTimeout(w.r.ProcessContext.Context(), time.Minute) ctx, cancel := context.WithTimeout(w.r.ProcessContext.Context(), time.Minute)
defer cancel() defer cancel()
if scope := sentry.CurrentHub().Scope(); scope != nil {
scope.SetTag("room_id", w.roomID)
}
msgs, err := w.subscription.Fetch(1, nats.Context(ctx)) msgs, err := w.subscription.Fetch(1, nats.Context(ctx))
switch err { switch err {
case nil: case nil:
@ -239,6 +242,9 @@ func (w *worker) _next() {
return return
} }
if scope := sentry.CurrentHub().Scope(); scope != nil {
scope.SetTag("event_id", inputRoomEvent.Event.EventID())
}
roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Inc() roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Inc()
defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Dec() defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": w.roomID}).Dec()

View file

@ -20,6 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
@ -284,6 +285,15 @@ func (u *latestEventsUpdater) latestState() error {
"old_latest": u.oldLatest.EventIDs(), "old_latest": u.oldLatest.EventIDs(),
"new_latest": u.latest.EventIDs(), "new_latest": u.latest.EventIDs(),
}).Warnf("State reset detected (removing %d events)", removed) }).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 // Also work out the state before the event removes and the event