Log device ID after requests

This commit is contained in:
David Robertson 2023-06-23 17:35:39 +01:00
parent bdcffda18f
commit 2829a7ae45
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
2 changed files with 7 additions and 2 deletions

View File

@ -16,6 +16,7 @@ var (
// logging metadata for a single request
type data struct {
userID string
deviceID string
since int64
next int64
numRooms int
@ -37,13 +38,14 @@ func RequestContext(ctx context.Context) context.Context {
}
// add the user ID to this request context. Need to have called RequestContext first.
func SetRequestContextUserID(ctx context.Context, userID string) {
func SetRequestContextUserID(ctx context.Context, userID, deviceID string) {
d := ctx.Value(ctxData)
if d == nil {
return
}
da := d.(*data)
da.userID = userID
da.deviceID = deviceID
if hub := sentry.GetHubFromContext(ctx); hub != nil {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{Username: userID})
@ -79,6 +81,9 @@ func DecorateLogger(ctx context.Context, l *zerolog.Event) *zerolog.Event {
if da.userID != "" {
l = l.Str("u", da.userID)
}
if da.deviceID != "" {
l = l.Str("dev", da.deviceID)
}
if da.since >= 0 {
l = l.Int64("p", da.since)
}

View File

@ -263,7 +263,7 @@ func (h *SyncLiveHandler) serve(w http.ResponseWriter, req *http.Request) error
return herr
}
requestBody.SetPos(cpos)
internal.SetRequestContextUserID(req.Context(), conn.UserID)
internal.SetRequestContextUserID(req.Context(), conn.UserID, conn.DeviceID)
log := hlog.FromRequest(req).With().Str("user", conn.UserID).Int64("pos", cpos).Logger()
var timeout int