Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add sentry error handling #500

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ jobs:
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
WINDOWS_CREDENTIAL_ID_SIGNER: ${{ secrets.WINDOWS_CREDENTIAL_ID_SIGNER }}
ES_TOTP_SECRET: ${{ secrets.ES_TOTP_SECRET }}
# Sentry AUTH Token
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ on:
ES_TOTP_SECRET:
description: 'Password to decrypt the certificate file'
required: true

SENTRY_AUTH_TOKEN:
description: 'Sentry auth token'
required: true
SENTRY_DSN:
description: 'Sentry DSN to perform the requests'
required: true
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -92,6 +97,9 @@ jobs:
VITE_SEGMENT_CREATORS_HUB_API_KEY: ${{ secrets.VITE_SEGMENT_CREATORS_HUB_API_KEY }}
VITE_SEGMENT_INSPECTOR_API_KEY: ${{ secrets.VITE_SEGMENT_INSPECTOR_API_KEY }}
VITE_ALLOWED_EXTERNAL_ORIGINS: ${{ secrets.VITE_ALLOWED_EXTERNAL_ORIGINS }}
# Sentry AUTH Token
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

- name: Generate release version
id: version
Expand Down
3,485 changes: 2,841 additions & 644 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@reduxjs/toolkit": "^2.2.6",
"@sentry/wizard": "^4.2.0",
"@types/cmd-shim": "^5.0.2",
"@types/is-running": "^2.1.2",
"@types/node": "20.14.9",
Expand Down Expand Up @@ -74,6 +75,9 @@
"@dcl/sdk": "7.7.9",
"@ethersproject/hash": "^5.7.0",
"@segment/analytics-node": "^2.1.2",
"@sentry/electron": "^6.1.0",
"@sentry/react": "^9.5.0",
"@sentry/vite-plugin": "^3.2.2",
"cmd-shim": "^6.0.3",
"decentraland-connect": "^7.1.0",
"decentraland-crypto-fetch": "^2.0.1",
Expand Down
23 changes: 22 additions & 1 deletion packages/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app } from 'electron';
import * as Sentry from '@sentry/electron/main';
import { platform } from 'node:process';
import updater from 'electron-updater';
import log from 'electron-log/main';
Expand All @@ -14,6 +15,12 @@ import '/@/security-restrictions';

log.initialize();

if (import.meta.env.PROD) {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
});
}

/**
* Prevent electron from running multiple instances.
*/
Expand Down Expand Up @@ -91,14 +98,24 @@ if (import.meta.env.PROD) {
log.info(`[AutoUpdater] Download progress ${info.percent.toFixed(2)}%`);
});
updater.autoUpdater.on('error', err => {
Sentry.captureException(err, {
tags: { source: 'auto-updater' },
extra: { context: 'Electron auto-update process' },
});
log.error('[AutoUpdater] Error in auto-updater', err);
});
return updater.autoUpdater.checkForUpdatesAndNotify({
title: 'Update available',
body: 'New version was installed. Restart the app to apply changes.',
});
})
.catch(error => log.error('[AutoUpdater] Failed check and install updates:', error.message));
.catch(error => {
Sentry.captureException(error, {
tags: { source: 'auto-updater' },
extra: { context: 'Electron auto-update process main' },
});
log.error('[AutoUpdater] Failed check and install updates:', error.message);
});
} else {
log.info('Skipping updates check in DEV mode');
}
Expand All @@ -119,6 +136,10 @@ app.on('before-quit', async event => {
try {
await killAll();
} catch (error) {
Sentry.captureException(error, {
tags: { source: 'before-quit' },
extra: { context: 'Before quit error' },
});
log.error('[App] Failed to kill all servers:', error);
}
log.info('[App] Quit');
Expand Down
6 changes: 6 additions & 0 deletions packages/main/src/modules/handle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ipcMain } from 'electron';
import log from 'electron-log';
import * as Sentry from '@sentry/electron/main';

import type { Ipc, IpcError, IpcResult } from '/shared/types/ipc';

// wrapper for ipcMain.handle with types
Expand All @@ -20,6 +22,10 @@ export async function handle<T extends keyof Ipc>(
return result;
} catch (error: any) {
log.error(`[IPC] channel=${channel} error=${error.message}`);
Sentry.captureException(error, {
tags: { source: 'ipc-handle' },
extra: { channel },
});
const result: IpcError = {
success: false,
error: error.message,
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/modules/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import * as Sentry from '@sentry/electron/main';
import fs from 'fs/promises';
import log from 'electron-log/main';
import { future } from 'fp-future';
Expand All @@ -23,6 +24,9 @@ export async function runMigrations() {
log.info('[Migrations] Migrations completed');
migrationsFuture.resolve();
} catch (error) {
Sentry.captureException(error, {
tags: { source: 'migrations' },
});
const err = error instanceof Error ? error : new Error(String(error));
migrationsFuture.reject(err);
throw error;
Expand Down
8 changes: 8 additions & 0 deletions packages/main/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sentryVitePlugin } from '@sentry/vite-plugin';
import { node } from '../../.electron-vendors.cache.json';
import { join } from 'node:path';

Expand Down Expand Up @@ -37,6 +38,13 @@ const config = {
emptyOutDir: true,
reportCompressedSize: false,
},
plugins: [
sentryVitePlugin({
org: 'decentraland',
project: 'creator-hub',
disable: process.env.MODE === 'development' || process.env.DRY_RUN,
}),
],
};

export default config;
11 changes: 9 additions & 2 deletions packages/preload/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sentryVitePlugin } from '@sentry/vite-plugin';
import { chrome } from '../../.electron-vendors.cache.json';
import { preload } from 'unplugin-auto-expose';
import { join } from 'node:path';
Expand Down Expand Up @@ -39,8 +40,14 @@ const config = {
emptyOutDir: true,
reportCompressedSize: false,
},

plugins: [preload.vite()],
plugins: [
preload.vite(),
sentryVitePlugin({
org: 'decentraland',
project: 'creator-hub',
disable: process.env.MODE === 'development' || process.env.DRY_RUN,
}),
],
};

export default config;
21 changes: 21 additions & 0 deletions packages/renderer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@ import { DocsPage } from '/@/components/DocsPage';
import { Install } from '/@/components/Install';
import { Snackbar } from '/@/components/Snackbar';

import { init as reactInit } from '@sentry/react';
import {
init as SentryInit,
browserTracingIntegration,
replayIntegration,
} from '@sentry/electron/renderer';

import '/@/themes';

const container = document.getElementById('app')!;
const root = createRoot(container);

if (import.meta.env.PROD) {
SentryInit(
{
integrations: [browserTracingIntegration(), replayIntegration()],
release: import.meta.env.VITE_APP_VERSION,
tracesSampleRate: 0.001,
replaysSessionSampleRate: 0.01,
replaysOnErrorSampleRate: 0.01,
enabled: import.meta.env.PROD,
},
reactInit as any,
);
}

root.render(
<React.StrictMode>
<StoreProvider store={store}>
Expand Down
6 changes: 6 additions & 0 deletions packages/renderer/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */

import { sentryVitePlugin } from '@sentry/vite-plugin';
import { chrome } from '../../.electron-vendors.cache.json';
import react from '@vitejs/plugin-react';
import { renderer } from 'unplugin-auto-expose';
Expand Down Expand Up @@ -49,6 +50,11 @@ const config = {
renderer.vite({
preloadEntry: join(PACKAGE_ROOT, '../preload/src/index.ts'),
}),
sentryVitePlugin({
org: 'decentraland',
project: 'creator-hub',
disable: process.env.MODE === 'development' || process.env.DRY_RUN,
}),
],
};

Expand Down
Loading