Introduce const for the ss sentry context key

This commit is contained in:
David Robertson 2023-05-25 21:54:46 +01:00
parent d73f390961
commit c0e0f8400e
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
3 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,10 @@ import (
"time" "time"
) )
// SentryCtxKey is a namespace under which we can report arbitrary key-value pairs to
// sentry.
const SentryCtxKey = "sliding-sync"
// GetSentryHubFromContextOrDefault is a version of sentry.GetHubFromContext which // GetSentryHubFromContextOrDefault is a version of sentry.GetHubFromContext which
// automatically falls back to sentry.CurrentHub if the given context has not been // automatically falls back to sentry.CurrentHub if the given context has not been
// attached a hub. // attached a hub.

View File

@ -535,7 +535,7 @@ func (p *poller) parseRoomsResponse(res *SyncResponse) {
const warnMsg = "parseRoomsResponse: prepending state events to timeline after gappy poll" const warnMsg = "parseRoomsResponse: prepending state events to timeline after gappy poll"
logger.Warn().Str("room_id", roomID).Int("prependStateEvents", len(prependStateEvents)).Msg(warnMsg) logger.Warn().Str("room_id", roomID).Int("prependStateEvents", len(prependStateEvents)).Msg(warnMsg)
sentry.WithScope(func(scope *sentry.Scope) { sentry.WithScope(func(scope *sentry.Scope) {
scope.SetContext("sliding-sync", map[string]interface{}{ scope.SetContext(internal.SentryCtxKey, map[string]interface{}{
"room_id": roomID, "room_id": roomID,
"num_prepend_state_events": len(prependStateEvents), "num_prepend_state_events": len(prependStateEvents),
}) })

View File

@ -127,7 +127,7 @@ func NewInviteData(ctx context.Context, userID, roomID string, inviteState []jso
logger.Error().Str("invitee", userID).Str("room", roomID).Int("num_invite_state", len(inviteState)).Msg(errMsg) logger.Error().Str("invitee", userID).Str("room", roomID).Int("num_invite_state", len(inviteState)).Msg(errMsg)
hub := internal.GetSentryHubFromContextOrDefault(ctx) hub := internal.GetSentryHubFromContextOrDefault(ctx)
hub.WithScope(func(scope *sentry.Scope) { hub.WithScope(func(scope *sentry.Scope) {
scope.SetContext("sliding-sync", map[string]interface{}{ scope.SetContext(internal.SentryCtxKey, map[string]interface{}{
"invitee": userID, "invitee": userID,
"room": roomID, "room": roomID,
"num_invite_state": len(inviteState), "num_invite_state": len(inviteState),