add api for access log events

This commit is contained in:
pascal
2026-01-29 14:27:57 +01:00
parent f204da0d68
commit 8e0b7b6c25
23 changed files with 745 additions and 189 deletions

View File

@@ -5,6 +5,8 @@ import (
"net/http"
"time"
"github.com/rs/xid"
"github.com/netbirdio/netbird/proxy/internal/auth"
"github.com/netbirdio/netbird/proxy/internal/proxy"
)
@@ -31,8 +33,10 @@ func (l *Logger) Middleware(next http.Handler) http.Handler {
host = r.Host
}
l.log(r.Context(), logEntry{
entry := logEntry{
ID: xid.New().String(),
ServiceId: proxy.ServiceIdFromContext(r.Context()),
AccountID: proxy.AccountIdFromContext(r.Context()),
Host: host,
Path: r.URL.Path,
DurationMs: duration.Milliseconds(),
@@ -42,6 +46,7 @@ func (l *Logger) Middleware(next http.Handler) http.Handler {
AuthMechanism: auth.MethodFromContext(r.Context()).String(),
UserId: auth.UserFromContext(r.Context()),
AuthSuccess: sw.status != http.StatusUnauthorized && sw.status != http.StatusForbidden,
})
}
l.log(r.Context(), entry)
})
}