8000 feat: extend request logs with auth & DB info by ibetitsmike · Pull Request #17304 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: extend request logs with auth & DB info #17304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 15, 2025
Merged
Prev Previous commit
Next Next commit
protected user map on request with mutex
  • Loading branch information
ibetitsmike committed Apr 14, 2025
commit a8b8b96f86e8293e5ab2f99cdf05ef4a2088128f
7 changes: 7 additions & 0 deletions coderd/httpmw/loggermw/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"sync"
"time"

"cdr.dev/slog"
Expand Down Expand Up @@ -71,6 +72,7 @@ type SlogRequestLogger struct {
written bool
message string
start time.Time
mu sync.RWMutex
actors map[rbac.SubjectType]rbac.Subject
}

Expand All @@ -91,10 +93,15 @@ func (c *SlogRequestLogger) WithFields(fields ...slog.Field) {
}

func (c *SlogRequestLogger) WithAuthContext(actor rbac.Subject) {
c.mu.Lock()
defer c.mu.Unlock()
c.actors[actor.Type] = actor
}

func (c *SlogRequestLogger) addAuthContextFields() {
c.mu.RLock()
defer c.mu.RUnlock()

usr, ok := c.actors[rbac.SubjectTypeUser]
if ok {
c.log = c.log.With(
Expand Down
0