(core) Improve debug logging related for client-side errors and sandbox crashes.

Summary:
- Include docId when available for client-side error reporting
- Distinguish sandbox crashes from forced exits

Test Plan: Tested manually

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3373
This commit is contained in:
Dmitry S 2022-04-11 09:52:34 -04:00
parent 859c593448
commit cedcdc6bff
3 changed files with 9 additions and 1 deletions

View File

@ -177,11 +177,13 @@ export function setUpErrorHandling(doReportError = reportError, koUtil?: any) {
*/ */
function _logError(error: Error|string) { function _logError(error: Error|string) {
if (!pageHasHome()) { return; } if (!pageHasHome()) { return; }
const docId = G.window.gristDocPageModel?.currentDocId?.get();
fetchFromHome('/api/log', { fetchFromHome('/api/log', {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
// Errors don't stringify, so pick out properties explicitly for errors. // Errors don't stringify, so pick out properties explicitly for errors.
event: (error instanceof Error) ? pick(error, Object.getOwnPropertyNames(error)) : error, event: (error instanceof Error) ? pick(error, Object.getOwnPropertyNames(error)) : error,
docId,
page: G.window.location.href, page: G.window.location.href,
browser: pick(G.window.navigator, ['language', 'platform', 'userAgent']) browser: pick(G.window.navigator, ['language', 'platform', 'userAgent'])
}), }),

View File

@ -576,6 +576,7 @@ export class FlexServer implements GristServer {
const mreq = req as RequestWithLogin; const mreq = req as RequestWithLogin;
log.rawWarn('client error', { log.rawWarn('client error', {
event: req.body.event, event: req.body.event,
docId: req.body.docId,
page: req.body.page, page: req.body.page,
browser: req.body.browser, browser: req.body.browser,
org: mreq.org, org: mreq.org,

View File

@ -233,8 +233,13 @@ export class NSandbox implements ISandbox {
} }
private _onExit(code: number, signal: string) { private _onExit(code: number, signal: string) {
const expected = this._isWriteClosed;
this._close(); this._close();
log.rawDebug(`Sandbox exited with code ${code} signal ${signal}`, this._logMeta); if (expected) {
log.rawDebug(`Sandbox exited with code ${code} signal ${signal}`, this._logMeta);
} else {
log.rawWarn(`Sandbox unexpectedly exited with code ${code} signal ${signal}`, this._logMeta);
}
} }