Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
use new crash reporter api
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver authored and bbondy committed Oct 6, 2017
1 parent 434b023 commit 8137a17
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 34 deletions.
77 changes: 77 additions & 0 deletions app/common/tracing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* 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 http://mozilla.org/MPL/2.0/. */

/* global performance */

let nodeTimer
if (typeof performance === 'undefined') {
nodeTimer = {
now: function () {
const NS_PER_SEC = 1e9
const NS_PER_MS = 1e6
const time = process.hrtime()
const seconds = time[0]
const nanoseconds = time[1] + (seconds * NS_PER_SEC)
return nanoseconds / NS_PER_MS
}
}
}
const timer = nodeTimer || performance

const filterArgs = function (args) {
const filteredArgs = []
for (let i = 0; i < args.length; i++) {
if (typeof args === 'object') {
filteredArgs[i] = '[Filtered]'
} else {
filteredArgs[i] = args[i]
}
}
return filteredArgs
}

exports.trace = (obj, ...args) => {
let filter = filterArgs
let metadata = {}
for (let i = 0; i < args.length; i++) {
if (typeof args[i] === 'function') {
filter = args[i]
} else if (typeof args[i] === 'object') {
metadata = args[i]
} else {
console.warn('invalid argument for trace: ' + args[i])
}
}

let handler = {
get (target, propKey, receiver) {
const propValue = target[propKey]
if (typeof propValue !== 'function') {
return propValue
}
return function (...fnArgs) {
metadata.name = propKey
muon.crashReporter.setCrashKeyValue('javascript-info', JSON.stringify(metadata))
let result, end, exception
const start = timer.now()
try {
result = propValue.apply(this, fnArgs)
end = timer.now()
metadata.durationMS = Math.ceil(end - start)
} catch (e) {
metadata.args = filter(fnArgs)
metadata.stack = e.stack != null ? e.stack : e.name + ': ' + e.message
exception = e
}
muon.crashReporter.setCrashKeyValue('javascript-info', JSON.stringify(metadata))
if (exception) {
muon.crashReporter.dumpWithoutCrashing()
throw exception
}
return result
}
}
}
return new Proxy(obj, handler)
}
40 changes: 27 additions & 13 deletions app/crash-herald.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const appConfig = require('../js/constants/appConfig')
const buildConfig = require('../js/constants/buildConfig')
const crashReporter = require('electron').crashReporter
const Channel = require('./channel')

exports.init = () => {
const options = {
productName: 'Brave Developers',
companyName: 'Brave.com',
submitURL: appConfig.crashes.crashSubmitUrl,
autoSubmit: true,
extra: {
node_env: process.env.NODE_ENV,
rev: buildConfig.BROWSER_LAPTOP_REV || 'unknown'
}
const version = buildConfig.BROWSER_LAPTOP_REV || 'unknown'
const channel = Channel.channel()

const crashKeys = {
'node-env': process.env.NODE_ENV,
'_version': version,
'channel': channel
}

const initCrashKeys = () => {
for (let key in crashKeys) {
muon.crashReporter.setCrashKeyValue(key, crashKeys[key])
}
}

exports.init = (enabled) => {
initCrashKeys()
const {app} = require('electron')
// set muon-app-version switch to pass version to renderer processes
app.commandLine.appendSwitch('muon-app-version', version)
app.commandLine.appendSwitch('muon-app-channel', channel)
muon.crashReporter.setEnabled(enabled)
if (enabled) {
console.log('Crash reporting enabled')
} else {
console.log('Crash reporting disabled')
}
crashReporter.start(options)
}
20 changes: 9 additions & 11 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

let ready = false

// Setup the crash handling
const CrashHerald = require('./crash-herald')
const telemetry = require('./telemetry')

Expand All @@ -20,7 +19,8 @@ const handleUncaughtError = (error) => {
message = 'Uncaught Exception:\n' + stack
console.error('An uncaught exception occurred in the main process ' + message)

// TODO(bridiver) - this should also send a notification to Brave
muon.crashReporter.setCrashKeyValue('javascript-info', JSON.stringify({stack}))
muon.crashReporter.dumpWithoutCrashing()

if (!ready) {
console.error('Waiting 60 seconds for process to load')
Expand Down Expand Up @@ -71,6 +71,7 @@ const locale = require('./locale')
const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const settings = require('../js/constants/settings')
const {getSetting} = require('../js/settings')
const BookmarksExporter = require('./browser/bookmarksExporter')
const siteUtil = require('../js/state/siteUtil')

Expand All @@ -96,18 +97,15 @@ let loadAppStatePromise = SessionStore.loadAppState()

// Some settings must be set right away on startup, those settings should be handled here.
loadAppStatePromise.then((initialImmutableState) => {
telemetry.setCheckpointAndReport('state-loaded')
const {HARDWARE_ACCELERATION_ENABLED, SMOOTH_SCROLL_ENABLED, SEND_CRASH_REPORTS} = require('../js/constants/settings')
if (initialImmutableState.getIn(['settings', HARDWARE_ACCELERATION_ENABLED]) === false) {
CrashHerald.init(getSetting(SEND_CRASH_REPORTS, initialImmutableState.get('settings')))

telemetry.setCheckpointAndReport('state-loaded')
if (getSetting(HARDWARE_ACCELERATION_ENABLED, initialImmutableState.get('settings')) === false) {
app.disableHardwareAcceleration()
}
if (initialImmutableState.getIn(['settings', SEND_CRASH_REPORTS]) !== false) {
console.log('Crash reporting enabled')
CrashHerald.init()
} else {
console.log('Crash reporting disabled')
}
if (initialImmutableState.getIn(['settings', SMOOTH_SCROLL_ENABLED]) === false) {

if (getSetting(SMOOTH_SCROLL_ENABLED, initialImmutableState.get('settings')) === false) {
app.commandLine.appendSwitch('disable-smooth-scrolling')
}
})
Expand Down
4 changes: 0 additions & 4 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {getTargetAboutUrl} = require('../lib/appUrlUtil')
// BRAVE_UPDATE_HOST should be set to the host name for the auto-updater server
const updateHost = process.env.BRAVE_UPDATE_HOST || 'https://brave-laptop-updates.global.ssl.fastly.net'
const winUpdateHost = process.env.BRAVE_WIN_UPDATE_HOST || 'https://brave-download.global.ssl.fastly.net'
const crashURL = process.env.BRAVE_CRASH_URL || 'https://brave-laptop-updates.herokuapp.com/1/crashes'
const adHost = process.env.AD_HOST || 'https://oip.brave.com'
const isTest = process.env.NODE_ENV === 'test'

Expand Down Expand Up @@ -91,9 +90,6 @@ module.exports = {
enabled: false,
url: adHost
},
crashes: {
crashSubmitUrl: crashURL
},
payments: {
delayNotificationTryPayments: 1000 * 60 * 60 * 24 * 10 // 10 days (from firstRunTimestamp)
},
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brave",
"version": "0.19.30",
"version": "0.20.1",

This comment has been minimized.

Copy link
@NejcZdovc

NejcZdovc Oct 6, 2017

Contributor

@bbondy be careful, version was changed but we are on 0.19 brach

"description": "Brave laptop and desktop browser",
"main": "./app/index.js",
"config": {
Expand All @@ -26,10 +26,10 @@
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "standard",
"postinstall": "npm run download-sync-client && webpack",
"start-log": "node ./tools/start.js --user-data-dir=brave-development --enable-logging=stderr --v=1 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start": "node ./tools/start.js --user-data-dir=brave-development --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start2": "node ./tools/start.js --user-data-dir=brave-development-2 --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start-brk": "node ./tools/start.js --debug-brk=5858 -enable-logging --v=0 --enable-dcheck --user-data-dir=brave-development",
"start-log": "node ./tools/start.js --user-data-dir-name=brave-development --enable-logging=stderr --v=1 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start": "node ./tools/start.js --user-data-dir-name=brave-development --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start2": "node ./tools/start.js --user-data-dir-name=brave-development-2 --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",
"start-brk": "node ./tools/start.js --debug-brk=5858 -enable-logging --v=0 --enable-dcheck --user-data-dir-name=brave-development",
"test": "cross-env NODE_ENV=test mocha \"test/**/*Test.js\"",
"testsuite": "node ./tools/test.js",
"unittest": "cross-env NODE_ENV=test mocha \"test/unit/**/*Test.js\"",
Expand Down
2 changes: 1 addition & 1 deletion tools/utilAppRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function runUtilApp (cmd, file, stdioOptions) {
}
cmd = cmd.split(' ')
if (process.env.NODE_ENV === 'development') {
cmd.push('--user-data-dir=brave-development')
cmd.push('--user-data-dir-name=brave-development')
}
const utilApp = proc.spawnSync('electron', [utilAppDir].concat(cmd), options)
if (utilApp.error) {
Expand Down

0 comments on commit 8137a17

Please sign in to comment.