From 1423236de3d18610d9d6a7b80af831d8cb0ff17f Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Tue, 22 Oct 2024 17:05:55 +0100 Subject: [PATCH] avoid slog.Logger().With --- lib/srv/app/aws/handler.go | 2 +- lib/srv/app/azure/handler.go | 4 ++-- lib/srv/app/gcp/handler.go | 4 ++-- lib/srv/app/server.go | 4 ++-- lib/srv/app/session.go | 16 +++++++--------- lib/srv/app/transport.go | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/srv/app/aws/handler.go b/lib/srv/app/aws/handler.go index 5539f7811a698..27d6e50882e9a 100644 --- a/lib/srv/app/aws/handler.go +++ b/lib/srv/app/aws/handler.go @@ -225,7 +225,7 @@ func (s *signerHandler) emitAudit(sessCtx *common.SessionContext, req *http.Requ } if auditErr != nil { // log but don't return the error, because we already handed off request/response handling to the oxy forwarder. - s.Log.With("error", auditErr).WarnContext(req.Context(), "Failed to emit audit event.") + s.Log.WarnContext(req.Context(), "Failed to emit audit event.", "error", auditErr) } } diff --git a/lib/srv/app/azure/handler.go b/lib/srv/app/azure/handler.go index c758fb16ae99c..9c5cc2f1c4314 100644 --- a/lib/srv/app/azure/handler.go +++ b/lib/srv/app/azure/handler.go @@ -239,11 +239,11 @@ func (s *handler) replaceAuthHeaders(r *http.Request, sessionCtx *common.Session return trace.Wrap(err, "failed to parse Authorization header") } - s.Log.With( + s.Log.DebugContext(r.Context(), "Processing request.", "session_id", sessionCtx.Identity.RouteToApp.SessionID, "azure_identity", sessionCtx.Identity.RouteToApp.AzureIdentity, "claims", claims, - ).DebugContext(r.Context(), "Processing request.") + ) token, err := s.getToken(r.Context(), sessionCtx.Identity.RouteToApp.AzureIdentity, claims.Resource) if err != nil { return trace.Wrap(err) diff --git a/lib/srv/app/gcp/handler.go b/lib/srv/app/gcp/handler.go index 46c99457f78bb..ebafa0faf07cc 100644 --- a/lib/srv/app/gcp/handler.go +++ b/lib/srv/app/gcp/handler.go @@ -172,10 +172,10 @@ func (s *handler) serveHTTP(w http.ResponseWriter, req *http.Request) error { if err != nil { return trace.Wrap(err) } - s.Log.With( + s.Log.DebugContext(req.Context(), "Processing request", "session_id", sessionCtx.Identity.RouteToApp.SessionID, "gcp_service_account", sessionCtx.Identity.RouteToApp.GCPServiceAccount, - ).DebugContext(req.Context(), "Processing request") + ) fwdRequest, err := s.prepareForwardRequest(req, sessionCtx) if err != nil { diff --git a/lib/srv/app/server.go b/lib/srv/app/server.go index 6f976189ec80a..83684289cdb3b 100644 --- a/lib/srv/app/server.go +++ b/lib/srv/app/server.go @@ -234,7 +234,7 @@ func (s *Server) startApp(ctx context.Context, app types.Application) error { if err := s.startHeartbeat(ctx, app); err != nil { return trace.Wrap(err) } - s.log.With("app", app).DebugContext(ctx, "App started.") + s.log.DebugContext(ctx, "App started.", "app", app) return nil } @@ -244,7 +244,7 @@ func (s *Server) stopApp(ctx context.Context, name string) error { if err := s.stopHeartbeat(name); err != nil { return trace.Wrap(err) } - s.log.With("app", name).DebugContext(ctx, "App stopped.") + s.log.DebugContext(ctx, "App stopped.", "app", name) return nil } diff --git a/lib/srv/app/session.go b/lib/srv/app/session.go index 573745e9cb0a7..f1b53f3994f8f 100644 --- a/lib/srv/app/session.go +++ b/lib/srv/app/session.go @@ -106,7 +106,7 @@ func (c *ConnectionsHandler) newSessionChunk(ctx context.Context, identity *tlsc legacyLogger: c.legacyLogger, } - sess.log.With("session_id", sess.id).DebugContext(ctx, "Creating app session chunk") + sess.log.DebugContext(ctx, "Creating app session chunk", "session_id", sess.id) // Create a session tracker so that other services, such as the // session upload completer, can track the session chunk's lifetime. @@ -143,7 +143,7 @@ func (c *ConnectionsHandler) newSessionChunk(ctx context.Context, identity *tlsc return nil, trace.Wrap(err) } - sess.log.With("session_id", sess.id).DebugContext(ctx, "Created app session chunk") + sess.log.DebugContext(ctx, "Created app session chunk", "session_id", sess.id) return sess, nil } @@ -266,24 +266,22 @@ func (s *sessionChunk) close(ctx context.Context) error { if s.inflight == 0 { break } else if time.Now().After(deadline) { - s.log.With( + s.log.DebugContext(ctx, "Timeout expired, forcibly closing session chunk", "session_id", s.id, "inflight_requests", s.inflight, - ).DebugContext(ctx, "Timeout expired, forcibly closing session chunk") + ) break } - s.log.With( + s.log.DebugContext(ctx, "Waiting to close session chunk", "session_id", s.id, "inflight_requests", s.inflight, - ).DebugContext(ctx, "Waiting to close session chunk") + ) s.inflightCond.Wait() } s.inflight = -1 s.inflightCond.L.Unlock() close(s.closeC) - s.log.With( - "session_id", s.id, - ).DebugContext(ctx, "Closed session chunk") + s.log.DebugContext(ctx, "Closed session chunk", "session_id", s.id) return trace.Wrap(s.streamCloser.Close(ctx)) } diff --git a/lib/srv/app/transport.go b/lib/srv/app/transport.go index e78235303b71a..d019af70dbe9f 100644 --- a/lib/srv/app/transport.go +++ b/lib/srv/app/transport.go @@ -185,7 +185,7 @@ func rewriteHeaders(r *http.Request, c *transportConfig) { } for _, header := range c.app.GetRewrite().Headers { if common.IsReservedHeader(header.Name) { - c.log.With("header_name", header.Name).DebugContext(r.Context(), "Not rewriting Teleport reserved header") + c.log.DebugContext(r.Context(), "Not rewriting Teleport reserved header", "header_name", header.Name) continue } values, err := services.ApplyValueTraits(header.Value, c.traits)