Skip to content

Commit

Permalink
avoid slog.Logger().With
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed Oct 22, 2024
1 parent 0afad81 commit 1423236
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/srv/app/aws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/srv/app/azure/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/app/gcp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
16 changes: 7 additions & 9 deletions lib/srv/app/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion lib/srv/app/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1423236

Please sign in to comment.