Skip to content

Commit

Permalink
Merge pull request #137 from baruchiro/SentryReportProblem
Browse files Browse the repository at this point in the history
Sentry report problem
  • Loading branch information
baruchiro authored Mar 4, 2020
2 parents 8df1a30 + 056343b commit 12cf7c8
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 65 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const globals = require('./globals')

module.exports = {
root: true,

Expand All @@ -14,7 +16,11 @@ module.exports = {
extends: ['airbnb-base', 'plugin:vue/recommended'],

globals: {
__static: true,
__static: 'writable',
...globals.reduce((prev, curr) => {
prev[curr] = 'readonly';
return prev;
}, {}),
},

plugins: [
Expand Down
5 changes: 5 additions & 0 deletions globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = [
'SENTRY_DSN',
'GOOGLE_CLIENT_ID',
'GOOGLE_CLIENT_SECRET',
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"private": true,
"scripts": {
"serve": "vue-cli-service electron:serve",
"prebuild": "node scripts/prebuild.js",
"build": "vue-cli-service electron:build",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
Expand All @@ -23,6 +22,7 @@
],
"dependencies": {
"@getstation/electron-google-oauth2": "2.1.0",
"@sentry/electron": "^1.2.1",
"core-js": "^3.4.4",
"download-chromium": "^2.2.0",
"electron-log": "^4.0.7",
Expand Down
30 changes: 0 additions & 30 deletions scripts/prebuild.js

This file was deleted.

113 changes: 113 additions & 0 deletions scripts/sentry-symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env node

/*
To upload debug information for native crashes when updating Electron, run:
npm install --save-dev @sentry/cli electron-download
node sentry-symbols.js
For more information, see https://docs.sentry.io/clients/electron/
*/
let SentryCli;
let download;

try {
SentryCli = require('@sentry/cli');
download = require('electron-download');
} catch (e) {
console.error('ERROR: Missing required packages, please run:');
console.error('npm install --save-dev @sentry/cli electron-download');
process.exit(1);
}

const VERSION = /\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?\b/i;
const SYMBOL_CACHE_FOLDER = '.electron-symbols';
const package = require('./package.json');
const sentryCli = new SentryCli('./sentry.properties');

async function main() {
let version = getElectronVersion();
if (!version) {
console.error('Cannot detect electron version, check package.json');
return;
}

console.log('We are starting to download all possible electron symbols');
console.log('We need it in order to symbolicate native crashes');
console.log(
'This step is only needed once whenever you update your electron version',
);
console.log('Just call this script again it should do everything for you.');

let zipPath = await downloadSymbols({
version,
platform: 'darwin',
arch: 'x64',
dsym: true,
});
await sentryCli.execute(['upload-dif', '-t', 'dsym', zipPath], true);

zipPath = await downloadSymbols({
version,
platform: 'win32',
arch: 'ia32',
symbols: true,
});
await sentryCli.execute(['upload-dif', '-t', 'breakpad', zipPath], true);

zipPath = await downloadSymbols({
version,
platform: 'win32',
arch: 'x64',
symbols: true,
});
await sentryCli.execute(['upload-dif', '-t', 'breakpad', zipPath], true);

zipPath = await downloadSymbols({
version,
platform: 'linux',
arch: 'x64',
symbols: true,
});
await sentryCli.execute(['upload-dif', '-t', 'breakpad', zipPath], true);

console.log('Finished downloading and uploading to Sentry');
console.log(`Feel free to delete the ${SYMBOL_CACHE_FOLDER}`);
}

function getElectronVersion() {
if (!package) {
return false;
}

let electronVersion =
(package.dependencies && package.dependencies.electron) ||
(package.devDependencies && package.devDependencies.electron);

if (!electronVersion) {
return false;
}

const matches = VERSION.exec(electronVersion);
return matches ? matches[0] : false;
}

async function downloadSymbols(options) {
return new Promise((resolve, reject) => {
download(
{
...options,
cache: SYMBOL_CACHE_FOLDER,
},
(err, zipPath) => {
if (err) {
reject(err);
} else {
resolve(zipPath);
}
},
);
});
}

main().catch(e => console.error(e));
3 changes: 3 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { app, BrowserWindow } from 'electron';
// eslint-disable-next-line import/no-extraneous-dependencies
import { createProtocol, installVueDevtools } from 'vue-cli-plugin-electron-builder/lib';
import CreateLogger from './logger';
import { initializeReporter } from './modules/reporting';
import './store';

initializeReporter();

const isDevelopment = process.env.NODE_ENV !== 'production';

// Keep a global reference of the window object, if you don't, the window will
Expand Down
52 changes: 44 additions & 8 deletions src/components/MainPage/ReportProblemDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
:rules="[titleRule]"
/>
</v-col>
<v-col>
<v-text-field
v-model="formData.email"
label="Email"
hint="We need your mail to contact you if you send a report"
persistent-hint
:rules="[emailExistRule, emailValidRule]"
/>
</v-col>
</v-row>
<v-row>
<v-col>
Expand Down Expand Up @@ -65,18 +74,25 @@
<v-btn
color="blue darken-1"
text
:disabled="!valid"
@click="open"
@click="openGithub"
>
Open Github Issue
</v-btn>
<v-btn
color="blue darken-1"
text
@click="sendReport"
>
Send Report
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script>
import { shell } from 'electron';
import { ReportProblem } from '@/modules/reporting';
import LogSheet from './LogSheet';
const createGithubIssueLink = (title, detailes, log) => {
Expand All @@ -98,6 +114,7 @@ ${log}
const defaultFormData = {
title: '',
email: '',
detailes: '',
attachLogs: true,
};
Expand All @@ -115,6 +132,7 @@ export default {
return {
valid: false,
sheet: false,
validateEmail: false,
formData: { ...defaultFormData },
raw: null,
};
Expand All @@ -126,33 +144,51 @@ export default {
},
},
watch: {
formData() {
this.$nextTick(this.$refs.form.validate);
},
dialog() {
this.$nextTick(this.resetForm);
},
},
methods: {
titleRule: (v) => !!v || 'Title is required',
emailExistRule(v) { return !this.validateEmail || !!v || 'Email is required'; },
emailValidRule(v) { return !this.validateEmail || /.+@.+\..+/.test(v) || 'Email must be valid'; },
detailesRule() {
return !!this.formData.detailes || this.formData.attachLogs || 'You must describe your report or attach the logs';
},
open() {
openGithub() {
this.validateEmail = false;
if (this.$refs.form.validate()) {
const url = createGithubIssueLink(this.formData.title, this.formData.detailes, this.formData.attachLogs ? this.raw : '');
const url = createGithubIssueLink(
this.formData.title,
this.formData.detailes,
this.formData.attachLogs ? this.raw : '',
);
this.$logger.info(`Open bug report url with title: ${this.formData.title}`);
shell.openExternal(url);
}
},
sendReport() {
this.validateEmail = true;
if (this.$refs.form.validate()) {
const eventId = ReportProblem(
this.formData.title,
this.formData.detailes,
this.formData.attachLogs ? this.raw : '',
this.formData.email,
);
this.$logger.info(`Problem reported. Event ${eventId}`);
this.dialog = false;
}
},
resetForm() {
this.raw = this.$logger.getLastLines(10);
this.formData = { ...defaultFormData };
this.validateEmail = false;
},
},
};
</script>

<style>
</style>
10 changes: 6 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Vue from 'vue';
// eslint-disable-next-line import/no-extraneous-dependencies
import electron from 'electron';
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';

import { initializeReporter } from './modules/reporting';
import './plugins/element';
import LoggerPlugin from './plugins/logger';
import vuetify from './plugins/vuetify';
import router from './router';
import store from './store';

initializeReporter();


const logger = electron.remote.getGlobal('logger');
Expand Down
34 changes: 34 additions & 0 deletions src/modules/reporting/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as Sentry from '@sentry/electron';

// https://github.com/getsentry/sentry-electron/issues/142
const { init } = (process.type === 'browser'
? require('@sentry/electron/dist/main')
: require('@sentry/electron/dist/renderer'));


const reporterConfiguration = {
dsn: SENTRY_DSN,
defaultIntegrations: false,
environment: process.env.NODE_ENV,
enableJavaScript: false,
enableNative: false,
enableUnresponsive: false,
};

export function initializeReporter() {
init(reporterConfiguration);
}

export function ReportProblem(title, body, logs, email, extra) {
return Sentry.captureEvent({
message: title,
logger: logs,
user: {
email,
},
extra: {
body,
...extra,
},
});
}
12 changes: 0 additions & 12 deletions src/modules/spreadsheet/client_secret.json

This file was deleted.

Loading

0 comments on commit 12cf7c8

Please sign in to comment.