Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Revert "[NEU-164] Remove @sentry/electron integration" #860

Merged
merged 4 commits into from
Mar 30, 2022
Merged
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
12 changes: 11 additions & 1 deletion .github/workflows/linux-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ jobs:
dist/template-linux-x64.json
dist/template-linux-x64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Sentry Release
if: startsWith(github.ref, 'refs/tags/')
run: |
curl -sL https://sentry.io/get-cli/ | bash
VERSION=$(node -p -e "require('./package.json').version")
sentry-cli releases new $VERSION
sentry-cli releases set-commits --auto $VERSION
sentry-cli releases finalize $VERSION
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
21 changes: 21 additions & 0 deletions main-src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ const {
} = require('electron');
const path = require('path');
const fs = require('fs-extra');
const isDev = require('electron-is-dev');
const settings = require('electron-settings');
const electronRemote = require('@electron/remote/main');
const rtlDetect = require('rtl-detect');
const Sentry = require('@sentry/electron/main');

const appJson = require('./constants/app-json');
const isMas = require('./libs/is-mas');
Expand Down Expand Up @@ -70,6 +72,21 @@ const {
setPreference,
} = require('./libs/preferences');

// Activate the Sentry Electron SDK as early as possible in every process.
const sentryEnabled = !isDev && getPreference('sentry');
if (sentryEnabled) {
// https://github.com/getsentry/sentry-electron/blob/06c9874584f7734fe6cb8297c6455cf6356d29d4/MIGRATION.md
Sentry.init({
dsn: process.env.ELECTRON_APP_SENTRY_DSN,
release: app.getVersion(),
autoSessionTracking: false,
// disable native crash reporting
// as it mostly reports Electron's bugs (upstream bugs)
integrations: (defaultIntegrations) => defaultIntegrations
.filter((i) => i.name !== Sentry.Integrations.SentryMinidump.Id),
});
}

const loadListeners = require('./listeners');
const loadInvokers = require('./invokers');

Expand Down Expand Up @@ -426,8 +443,10 @@ if (!gotTheLock) {
}).then(({ response }) => {
setPreference('privacyConsentAsked', true);
if (response === 0) {
setPreference('sentry', true);
setPreference('telemetry', true);
} else {
setPreference('sentry', false);
setPreference('telemetry', false);
}
}).catch(console.log); // eslint-disable-line
Expand Down Expand Up @@ -600,6 +619,8 @@ if (!gotTheLock) {
global.hibernateWhenUnused = hibernateWhenUnused;
global.hibernateWhenUnusedTimeout = hibernateWhenUnusedTimeout;

global.sentryEnabled = sentryEnabled;

// on Windows, if the display language is RTL language (Arabic, Hebrew, etc)
// the x bounds coordination is reversed
// so we have this to handle BrowserViews and related UI correctly
Expand Down
3 changes: 3 additions & 0 deletions main-src/libs/keytar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
const Sentry = require('@sentry/electron/main');

let keytar;

// on Linux
Expand All @@ -12,6 +14,7 @@ try {
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
}

module.exports = keytar;
5 changes: 4 additions & 1 deletion main-src/libs/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const defaultPreferences = {
rememberLastPageVisited: false,
runInBackground: false,
searchEngine: 'google',
sentry: false,
// branded apps (like Google/Microsoft) share browsing data by default
// https://github.com/webcatalog/webcatalog-app/issues/986
shareWorkspaceBrowsingData: isMenubarBrowser() || appJson.id.startsWith('group-') || appJson.id === 'clovery',
Expand Down Expand Up @@ -170,21 +171,23 @@ const initCachedPreferences = () => {
};

// shared-preferences.json includes:
// telemetry pref
// telemetry & sentry pref
// so that privacy consent prefs
// can be shared across WebCatalog and WebCatalog-Engine-based apps
// ignore this if error occurs
// so the more important initialization process can proceed
if (isWebcatalog()) {
const sharedPreferences = {
telemetry: false,
sentry: false,
};

try {
const sharedPreferencesPath = path.join(app.getPath('home'), '.webcatalog', 'shared-preferences.json');
if (fs.existsSync(sharedPreferencesPath)) {
const jsonContent = fs.readJsonSync(sharedPreferencesPath);
sharedPreferences.telemetry = Boolean(jsonContent.telemetry);
sharedPreferences.sentry = Boolean(jsonContent.sentry);
}
} catch (err) {
// eslint-disable-next-line no-console
Expand Down
5 changes: 3 additions & 2 deletions main-src/libs/system-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const { app } = require('electron');
const AutoLaunch = require('auto-launch');
const settings = require('electron-settings');
const Sentry = require('@sentry/electron/main');

const sendToAllWindows = require('./send-to-all-windows');

Expand All @@ -29,8 +30,7 @@ const checkAutoLauncherStatusAsync = () => {
sendToAllWindows('set-system-preference', 'openAtLogin', 'no');
})
.catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
sendToAllWindows('set-system-preference', 'openAtLogin', 'no');
});
}
Expand Down Expand Up @@ -98,6 +98,7 @@ const setSystemPreference = (name, value) => {
}
return null;
})
.catch((err) => Sentry.captureException(err))
.then(() => {
checkAutoLauncherStatusAsync();
});
Expand Down
4 changes: 2 additions & 2 deletions main-src/libs/window-shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const {
globalShortcut,
} = require('electron');
const Sentry = require('@sentry/electron/main');
const mainWindow = require('../windows/main');

const unset = (combinator) => {
Expand Down Expand Up @@ -32,8 +33,7 @@ const set = (combinator) => {
}
});
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
}
};

Expand Down
4 changes: 4 additions & 0 deletions main-src/libs/workspaces-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
const path = require('path');
const fs = require('fs-extra');

const Sentry = require('@sentry/electron/main');

const {
countWorkspaces,
createWorkspace,
Expand Down Expand Up @@ -276,6 +278,7 @@ const createWorkspaceView = (workspaceObj = {}) => {
.catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
});
}
});
Expand All @@ -294,6 +297,7 @@ const initWorkspaceViews = () => {
.catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@mui/lab": "5.0.0-alpha.75",
"@mui/material": "5.5.3",
"@types/react": "17.0.43",
"@sentry/electron": "3.0.6",
"@types/react-dom": "17.0.14",
"ace-builds": "1.4.14",
"amplitude-js": "8.17.0",
Expand All @@ -77,7 +78,7 @@
"electron-builder": "22.14.13",
"electron-chrome-extensions": "3.9.0",
"electron-context-menu": "3.1.2",
"electron-fetch": "1.8.0",
"electron-fetch": "1.7.4",
"electron-is-dev": "2.0.0",
"electron-notarize": "1.2.1",
"electron-positioner": "4.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/electron-fetch/lib/index.es.js b/node_modules/electron-fetch/lib/index.es.js
index 94d2264..6630bed 100644
index 3474009..effd43f 100644
--- a/node_modules/electron-fetch/lib/index.es.js
+++ b/node_modules/electron-fetch/lib/index.es.js
@@ -285,6 +285,21 @@ Body.prototype = {
Expand All @@ -25,10 +25,10 @@ index 94d2264..6630bed 100644
* Decode response as text, while automatically detecting the encoding and
* trying to decode to UTF-8 (non-spec api)
diff --git a/node_modules/electron-fetch/lib/index.js b/node_modules/electron-fetch/lib/index.js
index 6e3fb52..17bccf0 100644
index c9ea590..03b8558 100644
--- a/node_modules/electron-fetch/lib/index.js
+++ b/node_modules/electron-fetch/lib/index.js
@@ -313,6 +313,21 @@ Body.prototype = {
@@ -315,6 +315,21 @@ Body.prototype = {
return consumeBody.call(this);
},

Expand Down
4 changes: 2 additions & 2 deletions src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import amplitude from 'amplitude-js';
import { v5 as uuidv5 } from 'uuid';
import { app } from '@electron/remote';
import Sentry from '@sentry/electron/renderer';

import { getMachineIdAsync } from './invokers';

Expand All @@ -22,8 +23,7 @@ getMachineIdAsync()
amplitude.getInstance().setDeviceId(deviceId);
})
.catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
Sentry.captureException(err);
});

export default amplitude;
24 changes: 24 additions & 0 deletions src/components/preferences/section-telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import React from 'react';

import Divider from '@mui/material/Divider';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
Expand All @@ -14,14 +15,37 @@ import { useSelector } from 'react-redux';
import isWebcatalog from '../../../helpers/is-webcatalog';

import {
enqueueRequestRestartSnackbar,
requestSetPreference,
} from '../../../senders';

const SectionTelemetry = () => {
const sentry = useSelector((state) => state.preferences.sentry);
const telemetry = useSelector((state) => state.preferences.telemetry);

return (
<List disablePadding dense>
<ListItem>
<ListItemText
primary="Allow the app to send anonymous crash reports"
secondary={isWebcatalog()
? 'This preference is managed by WebCatalog app.'
: 'Help us quickly diagnose and fix bugs in the app.'}
/>
<ListItemSecondaryAction>
<Switch
edge="end"
color="primary"
checked={sentry}
disabled={isWebcatalog()}
onChange={(e) => {
requestSetPreference('sentry', e.target.checked);
enqueueRequestRestartSnackbar();
}}
/>
</ListItemSecondaryAction>
</ListItem>
<Divider />
<ListItem>
<ListItemText
primary="Allow the app to send anonymous usage data"
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ import getWorkspaceFriendlyName from './helpers/get-workspace-friendly-name';

import { getReactInitialStateAsync } from './invokers';

if (getStaticGlobal('sentryEnabled')) {
import('@sentry/electron/renderer')
.then((Sentry) => {
Sentry.init({});
})
.catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
});
}

const appJson = getStaticGlobal('appJson');

const AddWorkspace = React.lazy(() => import('./components/add-workspace'));
Expand Down
Loading