From febaa93dd23365ee7e52f4828194154f091affbd Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Tue, 18 Apr 2023 14:44:06 -0700 Subject: [PATCH] logging: Make `logging.info` log to Sentry We have a log line NotifTroubleshootingScreen: MailComposer reports a sent email. that I'd *thought* was getting sent to Sentry, but apparently not. The line is meant to help us detect potential cases where the user thought they'd contacted support through the app, but we don't see an email on our side. We're not aware of such cases yet, but in principle it could happen. Since it seems helpful to have a function for logging to Sentry at an "info" level, rewrite `logging.info` based on `logging.warn` and `logging.error` so it does that. That should cause that notif-troubleshooting line to go to Sentry. The one other callsite of `logging.info` is redundant with a breadcrumb added with the same information; remove it and an unexplained test assertion about it. --- src/api/apiFetch.js | 1 - src/message/__tests__/fetchActions-test.js | 7 ------- src/utils/logging.js | 22 +++++++++++++--------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/api/apiFetch.js b/src/api/apiFetch.js index 3ce7fbdaacc..b4411e3dc09 100644 --- a/src/api/apiFetch.js +++ b/src/api/apiFetch.js @@ -85,7 +85,6 @@ export const apiCall = async ( const { httpStatus, data } = error instanceof RequestError ? error : {}; const response = data !== undefined ? data : '(none, or not valid JSON)'; - logging.info({ route, params, httpStatus, response }); Sentry.addBreadcrumb({ category: 'api', level: 'info', diff --git a/src/message/__tests__/fetchActions-test.js b/src/message/__tests__/fetchActions-test.js index ef382682322..de76597afa2 100644 --- a/src/message/__tests__/fetchActions-test.js +++ b/src/message/__tests__/fetchActions-test.js @@ -392,19 +392,12 @@ describe('fetchActions', () => { // $FlowFixMe[prop-missing]: See mock in jest/globalFetch.js. fetch.mockResponseFailure(fetchError); - // $FlowFixMe[prop-missing]: Jest mock - logging.info.mockReturnValue(); await expect( store.dispatch( fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }), ), ).rejects.toThrow(fetchError); - - // $FlowFixMe[prop-missing]: Jest mock - expect(logging.info.mock.calls).toHaveLength(1); - // $FlowFixMe[prop-missing]: Jest mock - logging.info.mockReset(); }); }); diff --git a/src/utils/logging.js b/src/utils/logging.js index 3f48b800de6..5f28fe30d7f 100644 --- a/src/utils/logging.js +++ b/src/utils/logging.js @@ -214,16 +214,20 @@ export const warn: (event: string | Error, extras?: Extras) => void = makeLogFun /** * Log an event at "info" severity. * - * The event will be logged to the console as appropriate. - * - * This will *not* log any information to Sentry. Consider also calling - * `Sentry.addBreadcrumb`. + * The event will be logged to Sentry and/or the console as appropriate. * * See also: * * `logging.warn` and `logging.error` for logging at higher severity + * * `Sentry.addBreadcrumb`, to add background data to an eventual Sentry + * report, but without causing a Sentry report. + * + * @param event A string describing the nature of the event to be logged, or an + * exception whose `.message` is such a string. Related events should have + * identical such strings, when feasible. + * @param extras Diagnostic data which may differ between separate occurrences + * of the event. */ -export const info = (event: string | Error | { ... }) => { - if (config.enableErrorConsoleLogging) { - console.log(event); - } -}; +export const info: (event: string | Error, extras?: Extras) => void = makeLogFunction({ + consoleMethod: console.info, + severity: Severity.Info, +});