Skip to content

Commit

Permalink
Fix sentry not capturing context of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Oct 1, 2023
1 parent c9660fc commit 669ed07
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/src/util/analytics/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ export const logEvent = ({ level, message, error: ep, ...contextParam }: LogEven
const error = ep !== undefined ? (ep instanceof Error ? ep : new Error(`${ep}`)) : undefined;
const context = _.mapValues(contextParam, (v) => JSON.stringify(v ?? null, null, 2));

crashlytics().log(`${level}: ${message}`);
if (context) crashlytics().setAttributes(context);

Sentry.captureMessage(message, { level, extra: context });

// Sentry
if (error) {
Sentry.captureException(error);
crashlytics().recordError(error);
Sentry.captureException(error, { level, extra: { ...context, message } });
} else {
Sentry.captureMessage(message, { level, extra: context });
}

// Crashlytics
crashlytics().setAttributes(context);
crashlytics().log(`${level}: ${message}`);
if (error) crashlytics().recordError(error);

// Console
CONSOLE[level](
`Event: ${message}`,
JSON.stringify(
Expand Down

0 comments on commit 669ed07

Please sign in to comment.