diff --git a/app/server/lib/Authorizer.ts b/app/server/lib/Authorizer.ts index 6d321e51..a1030139 100644 --- a/app/server/lib/Authorizer.ts +++ b/app/server/lib/Authorizer.ts @@ -300,9 +300,17 @@ export async function addRequestUser(dbManager: HomeDBManager, permitStore: IPer mreq.users = [dbManager.makeFullUser(anon)]; } - log.debug("Auth[%s]: id %s email %s host %s path %s org %s%s", mreq.method, - mreq.userId, mreq.user?.loginEmail, mreq.get('host'), mreq.path, mreq.org, - customHostSession); + const meta = { + customHostSession, + method: mreq.method, + host: mreq.get('host'), + path: mreq.path, + org: mreq.org, + email: mreq.user?.loginEmail, + userId: mreq.userId, + altSessionId: mreq.altSessionId, + }; + log.rawDebug(`Auth[${meta.method}]: ${meta.host} ${meta.path}`, meta); return next(); } diff --git a/app/server/lib/Client.ts b/app/server/lib/Client.ts index ed46f56c..1c3d1cfd 100644 --- a/app/server/lib/Client.ts +++ b/app/server/lib/Client.ts @@ -365,6 +365,8 @@ export class Client { meta.age = Math.floor(moment.duration(moment().diff(this._firstLoginAt)).asDays()); } if (this._org) { meta.org = this._org; } + const altSessionId = this.getAltSessionId(); + if (altSessionId) { meta.altSessionId = altSessionId; } meta.clientId = this.clientId; // identifies a client connection, essentially a websocket meta.counter = this._counter; // identifies a GristWSConnection in the connected browser tab return meta; diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index ca6b90cc..fcc025ac 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -581,6 +581,7 @@ export class FlexServer implements GristServer { org: mreq.org, email: mreq.user && mreq.user.loginEmail, userId: mreq.userId, + altSessionId: mreq.altSessionId, }); return resp.status(200).send(); })); diff --git a/app/server/lib/GoogleExport.ts b/app/server/lib/GoogleExport.ts index 54ba28d0..f0545bbe 100644 --- a/app/server/lib/GoogleExport.ts +++ b/app/server/lib/GoogleExport.ts @@ -22,9 +22,11 @@ export async function exportToDrive( throw new Error("No access token - Can't send file to Google Drive"); } + const mreq = req as RequestWithLogin; const meta = { - docId : activeDoc.docName, - userId : (req as RequestWithLogin).userId + docId: activeDoc.docName, + userId: mreq.userId, + altSessionId: mreq.altSessionId, }; // Prepare file for exporting. log.debug(`Export to drive - Preparing file for export`, meta); diff --git a/app/server/lib/Sharing.ts b/app/server/lib/Sharing.ts index f61d989c..a4f28a87 100644 --- a/app/server/lib/Sharing.ts +++ b/app/server/lib/Sharing.ts @@ -243,6 +243,7 @@ export class Sharing { parentActionHash: null, // Gets set below by _actionHistory.recordNext... }; + const altSessionId = client?.getAltSessionId(); const logMeta = { actionNum, linkId: info.linkId, @@ -250,6 +251,7 @@ export class Sharing { numDocActions: localActionBundle.stored.length, numRows: localActionBundle.stored.reduce((n, env) => n + getNumRows(env[1]), 0), author: info.user, + ...(altSessionId ? {session: altSessionId}: {}), }; this._log.rawLog('debug', docSession, '_doApplyUserActions', logMeta); if (LOG_ACTION_BUNDLE) { diff --git a/app/server/lib/expressWrap.ts b/app/server/lib/expressWrap.ts index 6e634c6e..25964891 100644 --- a/app/server/lib/expressWrap.ts +++ b/app/server/lib/expressWrap.ts @@ -26,14 +26,17 @@ interface JsonErrorHandlerOptions { * Currently allows for toggling of logging request bodies and params. */ const buildJsonErrorHandler = (options: JsonErrorHandlerOptions = {}): express.ErrorRequestHandler => { + const {shouldLogBody, shouldLogParams} = options; return (err, req, res, _next) => { const mreq = req as RequestWithLogin; - log.warn( - "Error during api call to %s: (%s)%s%s%s", - req.path, err.message, mreq.userId !== undefined ? ` user ${mreq.userId}` : '', - options.shouldLogParams !== false ? ` params ${JSON.stringify(req.params)}` : '', - options.shouldLogBody !== false ? ` body ${JSON.stringify(req.body)}` : '', - ); + const meta = { + path: mreq.path, + userId: mreq.userId, + altSessionId: mreq.altSessionId, + body: shouldLogBody !== false ? req.body : undefined, + params: shouldLogParams !== false ? req.params : undefined, + }; + log.rawWarn(`Error during api call to ${meta.path}: ${err.message}`, meta); let details = err.details && {...err.details}; const status = details?.status || err.status || 500; if (details) { diff --git a/app/server/lib/requestUtils.ts b/app/server/lib/requestUtils.ts index 7cf93243..718e12c7 100644 --- a/app/server/lib/requestUtils.ts +++ b/app/server/lib/requestUtils.ts @@ -186,6 +186,7 @@ export async function sendReply( log.rawDebug('api call', { url: req.url, userId: mreq.userId, + altSessionId: mreq.altSessionId, email: mreq.user && mreq.user.loginEmail, org: mreq.org, params: req.params, diff --git a/app/server/lib/uploads.ts b/app/server/lib/uploads.ts index de0f9f81..9dbdfd45 100644 --- a/app/server/lib/uploads.ts +++ b/app/server/lib/uploads.ts @@ -116,6 +116,7 @@ export async function handleOptionalUpload(req: Request, res: Response): Promise org: mreq.org, email: mreq.user && mreq.user.loginEmail, userId: mreq.userId, + altSessionId: mreq.altSessionId, }; log.rawDebug(`Prepared to receive upload into tmp dir ${tmpDir}`, meta);