Skip to content

Commit

Permalink
(core) Include altSessionId in logs
Browse files Browse the repository at this point in the history
Summary: Adds altSessionId to log output.

Test Plan: Tested manually.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3355
  • Loading branch information
georgegevoian committed Apr 8, 2022
1 parent bf8769b commit 4c5de16
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 11 deletions.
14 changes: 11 additions & 3 deletions app/server/lib/Authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions app/server/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/server/lib/FlexServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand Down
6 changes: 4 additions & 2 deletions app/server/lib/GoogleExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/server/lib/Sharing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ export class Sharing {
parentActionHash: null, // Gets set below by _actionHistory.recordNext...
};

const altSessionId = client?.getAltSessionId();
const logMeta = {
actionNum,
linkId: info.linkId,
otherId: info.otherId,
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) {
Expand Down
15 changes: 9 additions & 6 deletions app/server/lib/expressWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/server/lib/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export async function sendReply<T>(
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,
Expand Down
1 change: 1 addition & 0 deletions app/server/lib/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4c5de16

Please sign in to comment.