diff --git a/lib/srv/ctx.go b/lib/srv/ctx.go index e0f5fd17ceee7..4ad50010c46dd 100644 --- a/lib/srv/ctx.go +++ b/lib/srv/ctx.go @@ -322,6 +322,18 @@ func NewServerContext(ctx context.Context, parent *sshutils.ConnectionContext, s cancel: cancel, } + fields := log.Fields{ + "local": child.ServerConn.LocalAddr(), + "remote": child.ServerConn.RemoteAddr(), + "login": child.Identity.Login, + "teleportUser": child.Identity.TeleportUser, + "id": child.id, + } + child.Entry = log.WithFields(log.Fields{ + trace.Component: child.srv.Component(), + trace.ComponentFields: fields, + }) + authPref, err := srv.GetAccessPoint().GetAuthPreference(ctx) if err != nil { childErr := child.Close() @@ -332,13 +344,7 @@ func NewServerContext(ctx context.Context, parent *sshutils.ConnectionContext, s child.disconnectExpiredCert = identityContext.CertValidBefore } - fields := log.Fields{ - "local": child.ServerConn.LocalAddr(), - "remote": child.ServerConn.RemoteAddr(), - "login": child.Identity.Login, - "teleportUser": child.Identity.TeleportUser, - "id": child.id, - } + // Update log entry fields. if !child.disconnectExpiredCert.IsZero() { fields["cert"] = child.disconnectExpiredCert }