Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add analytics #482

Merged
merged 12 commits into from
Feb 16, 2018
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [0.4.3] - 2018-02-05
### Changed
* Renamed Cosmos UI to Cosmos Voyager. @nylira
* Added Google Analytics for testnet versions
* Added Sentry error reporting for testnet versions
13 changes: 13 additions & 0 deletions app/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@
<style>
<%= htmlWebpackPlugin.options.styles %>
</style>


<% if (htmlWebpackPlugin.options.enableAnalytics) { %>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-51029217-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-51029217-3');
</script>
<% } %>
30 changes: 24 additions & 6 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let semver = require('semver')
let event = require('event-to-promise')
let toml = require('toml')
let axios = require('axios')
let Raven = require('raven')

let pkg = require('../../../package.json')
let relayServer = require('./relayServer.js')
Expand Down Expand Up @@ -177,6 +178,8 @@ function startProcess (name, args, env) {
child.on('exit', (code) => !shuttingDown && log(`${name} exited with code ${code}`))
child.on('error', function (err) {
if (!(shuttingDown && err.code === 'ECONNRESET')) {
// TODO test
Raven.captureException(err)
// if we throw errors here, they are not handled by the main process
console.error('[Uncaught Exception] Child', name, 'produced an unhandled exception:', err)
console.log('Shutting down UI')
Expand Down Expand Up @@ -303,15 +306,16 @@ function setupLogging (root) {

if (!TEST) {
process.on('exit', shutdown)
// on uncaught exceptions we wait so the sentry event can be sent
process.on('uncaughtException', async function (err) {
await sleep(1000)
logError('[Uncaught Exception]', err)
console.error('[Uncaught Exception]', err)
await shutdown()
process.exit(1)
})
process.on('unhandledRejection', async function (err) {
await sleep(1000)
logError('[Unhandled Promise Rejection]', err)
console.error('[Unhandled Promise Rejection]', err)
await shutdown()
process.exit(1)
})
Expand Down Expand Up @@ -366,7 +370,21 @@ async function reconnect (seeds) {
return nodeIP
}

function setupAnalytics () {
let networkIsWhitelisted = config.analytics_networks.indexOf(config.default_network) !== -1
if (networkIsWhitelisted) {
log('Adding analytics')
}

// only enable sending of error events in production setups and if the network is a testnet
Raven.config(networkIsWhitelisted && process.env.NODE_ENV === 'production' ? config.sentry_dsn : '', {
captureUnhandledRejections: true
}).install()
}

async function main () {
setupAnalytics()

let appVersionPath = join(root, 'app_version')
let genesisPath = join(root, 'genesis.json')
let configPath = join(root, 'config.toml')
Expand Down Expand Up @@ -399,7 +417,7 @@ async function main () {
// TODO: versions of the app with different data formats will need to learn how to
// migrate old data
throw Error(`Data was created with an incompatible app version
data=${existingVersion} app=${pkg.version}`)
data=${existingVersion} app=${pkg.version}`)
}
} else {
throw Error(`The data directory (${root}) has missing files`)
Expand Down Expand Up @@ -441,7 +459,7 @@ async function main () {
// TODO: semver check, or exact match?
if (gaiaVersion !== expectedGaiaVersion) {
throw Error(`Requires gaia ${expectedGaiaVersion}, but got ${gaiaVersion}.
Please update your gaia installation or build with a newer binary.`)
Please update your gaia installation or build with a newer binary.`)
}

// read chainId from genesis.json
Expand All @@ -457,8 +475,8 @@ async function main () {
} catch (e) {
throw new Error(`Can't open config.toml: ${e.message}`)
}
let config = toml.parse(configText)
let seeds = config.p2p.seeds.split(',').filter(x => x !== '')
let configTOML = toml.parse(configText)
let seeds = configTOML.p2p.seeds.split(',').filter(x => x !== '')
if (seeds.length === 0) {
throw new Error('No seeds specified in config.toml')
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/network.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
let { join } = require('path')
let { readFileSync } = require('fs')
let config = require('../../config.js')

// this network gets used if none is specified via the
// COSMOS_NETWORK env var
let DEFAULT_NETWORK = join(__dirname, '../networks/gaia-2')
let DEFAULT_NETWORK = join(__dirname, '../networks/' + config.default_network)
Copy link
Collaborator

@jbibla jbibla Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the space matter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which space?

Copy link
Collaborator

@jbibla jbibla Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. i misread.

let networkPath = process.env.COSMOS_NETWORK || DEFAULT_NETWORK

let genesisText = readFileSync(join(networkPath, 'genesis.json'), 'utf8')
Expand Down
17 changes: 17 additions & 0 deletions app/src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@ import Router from 'vue-router'
import Vuelidate from 'vuelidate'
import shrinkStacktrace from '../helpers/shrink-stacktrace.js'
import axios from 'axios'
import Raven from 'raven-js'
import {remote} from 'electron'

const config = require('../../../config')

import App from './App'
import routes from './routes'
import Node from './node'
import Store from './vuex/store'

// setup sentry remote error reporting on testnets
const networkIsWhitelisted = config.analytics_networks.indexOf(config.default_network) !== -1
Raven.config(networkIsWhitelisted && remote.getGlobal('process').env.NODE_ENV === 'production' ? config.sentry_dsn : '').install()

// handle uncaught errors
window.addEventListener('unhandledrejection', function (event) {
Raven.captureException(event.reason)
})
window.addEventListener('error', function (event) {
Raven.captureException(event.reason)
})
Vue.config.errorHandler = (error, vm, info) => {
Raven.captureException(error)
shrinkStacktrace(error)
return true
}

Vue.use(Electron)
Vue.use(Resource)
Vue.use(Router)
Expand Down
7 changes: 6 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ let config = {
overwrite: true,
platform: process.env.PLATFORM_TARGET || 'darwin,linux,win32',
packageManager: 'yarn'
}
},

default_network: 'gaia-2',
analytics_networks: ['gaia-2', 'gaia-3-dev', 'gaia-3'],
google_analytics: 'UA-51029217-3',
sentry_dsn: 'https://4dee9f70a7d94cc0959a265c45902d84:[email protected]/288169'
}

config.building.name = config.name
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"no-scroll": "^2.1.0",
"numeral": "^2.0.6",
"perfect-scrollbar": "^1.3.0",
"raven": "^2.4.1",
"raven-js": "^3.22.3",
"semver": "^5.4.1",
"shortid": "^2.2.8",
"stacktrace-js": "^2.0.0",
Expand Down
13 changes: 13 additions & 0 deletions test/unit/specs/App.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
jest.mock('renderer/node.js', () => () => require('../helpers/node_mock'))
jest.mock('electron', () => ({
require: jest.genMockFunction(),
match: jest.genMockFunction(),
app: jest.genMockFunction(),
remote: {
getGlobal: () => ({
env: {
NODE_ENV: 'test'
}
})
},
dialog: jest.genMockFunction()
}))

describe('App', () => {
it('has all dependencies', async done => {
Expand Down
3 changes: 1 addition & 2 deletions test/unit/specs/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ describe('Startup Process', () => {
} catch (_err) {
err = _err
}
expect(err.message).toBe(`Data was created with an incompatible app version
data=0.1.0 app=1.1.1`)
expect(err.message).toContain(`incompatible app version`)

let appVersion = fs.readFileSync(testRoot + 'app_version', 'utf8')
expect(appVersion).toBe('0.1.0')
Expand Down
3 changes: 2 additions & 1 deletion webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ let rendererConfig = {
appModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, 'app/node_modules')
: false,
styles: stylus(fs.readFileSync('./app/src/renderer/styles/index.styl', 'utf8')).import('./app/src/renderer/styles/variables.styl').render()
styles: stylus(fs.readFileSync('./app/src/renderer/styles/index.styl', 'utf8')).import('./app/src/renderer/styles/variables.styl').render(),
enableAnalytics: process.env.NODE_ENV === 'production' && settings.analytics_networks.indexOf(settings.default_network) !== -1
}),
new webpack.NoEmitOnErrorsPlugin(),
// warnings caused by websocket-stream, which has a server-part that is unavailable on the the client
Expand Down
42 changes: 40 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@ chardet@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"

charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"

chart.js@^2.6.0:
version "2.7.1"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-2.7.1.tgz#ae90b4aa4ff1f02decd6b1a2a8dabfd73c9f9886"
Expand Down Expand Up @@ -1948,6 +1952,10 @@ [email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/cross-unzip/-/cross-unzip-0.0.2.tgz#5183bc47a09559befcf98cc4657964999359372f"

crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"
Expand Down Expand Up @@ -4061,7 +4069,7 @@ is-binary-path@^1.0.0:
dependencies:
binary-extensions "^1.0.0"

is-buffer@^1.1.5:
is-buffer@^1.1.5, is-buffer@~1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"

Expand Down Expand Up @@ -5218,6 +5226,14 @@ md5.js@^1.3.4:
hash-base "^3.0.0"
inherits "^2.0.1"

md5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
dependencies:
charenc "~0.0.1"
crypt "~0.0.1"
is-buffer "~1.1.1"

mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
Expand Down Expand Up @@ -6685,6 +6701,20 @@ range-parser@^1.0.3, range-parser@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"

raven-js@^3.22.3:
version "3.22.3"
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.22.3.tgz#8330dcc102b699ffbc2f48790978b997bf4d8f75"

raven@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/raven/-/raven-2.4.1.tgz#7a6a6ff1c42d0a3892308f44c94273e7f88677fd"
dependencies:
cookie "0.3.1"
md5 "^2.2.1"
stack-trace "0.0.9"
timed-out "4.0.1"
uuid "3.0.0"

[email protected], raw-body@^2.3.0:
version "2.3.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89"
Expand Down Expand Up @@ -7575,6 +7605,10 @@ stack-generator@^2.0.1:
dependencies:
stackframe "^1.0.4"

[email protected]:
version "0.0.9"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.9.tgz#a8f6eaeca90674c333e7c43953f275b451510695"

stackframe@^1.0.3, stackframe@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.0.4.tgz#357b24a992f9427cba6b545d96a14ed2cbca187b"
Expand Down Expand Up @@ -7986,7 +8020,7 @@ time-stamp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-2.0.0.tgz#95c6a44530e15ba8d6f4a3ecb8c3a3fac46da357"

timed-out@^4.0.0:
timed-out@4.0.1, timed-out@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"

Expand Down Expand Up @@ -8329,6 +8363,10 @@ [email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"

[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728"

uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14"
Expand Down