(core) Include altSessionId in logs

Summary: Adds altSessionId to log output.

Test Plan: Tested manually.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3355
add-page-name
George Gevoian 2 years ago
parent bf8769bc42
commit 4c5de16e2d

@ -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();
}

@ -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;

@ -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();
}));

@ -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);

@ -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) {

@ -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) {

@ -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,

@ -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);

Loading…
Cancel
Save