Skip to content

Commit

Permalink
feat(GUI): use resin-raven in AnalyticsService
Browse files Browse the repository at this point in the history
This commit also removes bower.

Change-Type: patch
Fixes: #1027
  • Loading branch information
stefan-mihaila committed Apr 10, 2017
1 parent 07dad2a commit c4053c1
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 777 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install:
./scripts/build/docker/run-command.sh -r "${TARGET_ARCH}" -s "${PWD}" -c "make info && make electron-develop";
else
pip install codespell==1.9.2 awscli;
npm install -g bower asar;
npm install -g asar;
brew install afsctool jq;
make info;
travis_wait make electron-develop;
Expand Down
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ endif
endif
endif

# ---------------------------------------------------------------------
# Analytics
# ---------------------------------------------------------------------

ifndef ANALYTICS_SENTRY_TOKEN
$(warning No Sentry token found (ANALYTICS_SENTRY_TOKEN is not set))
endif

ifndef ANALYTICS_MIXPANEL_TOKEN
$(warning No Mixpanel token found (ANALYTICS_MIXPANEL_TOKEN is not set))
endif

# ---------------------------------------------------------------------
# Extra variables
# ---------------------------------------------------------------------
Expand Down Expand Up @@ -189,18 +201,27 @@ $(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/node_modu
-t node \
-s "$(TARGET_PLATFORM)"

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/bower_components: bower.json \
| $(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies
./scripts/build/dependencies-bower.sh -p -x $|

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app: \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/node_modules \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/bower_components \
| $(BUILD_DIRECTORY)
| $(BUILD_DIRECTORY) $(BUILD_TEMPORARY_DIRECTORY)
./scripts/build/electron-create-resources-app.sh -s . -o $@ \
-v $(APPLICATION_VERSION) \
-f "$(APPLICATION_FILES)"
$(foreach prerequisite,$^,$(call execute-command,cp -RLf $(prerequisite) $@))
cp -RLf $< $@

ifdef ANALYTICS_SENTRY_TOKEN
./scripts/build/jq-inplace.sh \
-c ".analytics.sentry.token = \"$(ANALYTICS_SENTRY_TOKEN)\"" \
-f $@/package.json \
-t $(BUILD_TEMPORARY_DIRECTORY)
endif

ifdef ANALYTICS_MIXPANEL_TOKEN
./scripts/build/jq-inplace.sh \
-c ".analytics.mixpanel.token = \"$(ANALYTICS_MIXPANEL_TOKEN)\"" \
-f $@/package.json \
-t $(BUILD_TEMPORARY_DIRECTORY)
endif

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app.asar: \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app \
Expand Down Expand Up @@ -484,7 +505,6 @@ electron-develop:
-v "$(ELECTRON_VERSION)" \
-t electron \
-s "$(TARGET_PLATFORM)"
./scripts/build/dependencies-bower.sh

help:
@echo "Available targets: $(TARGETS)"
Expand All @@ -510,6 +530,5 @@ clean:

distclean: clean
rm -rf node_modules
rm -rf bower_components

.DEFAULT_GOAL = help
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ matrix:
install:
- ps: Install-Product node $env:nodejs_version x64
- npm install -g [email protected]
- npm install -g bower rimraf asar
- npm install -g rimraf asar
- choco install nsis -version 2.51
- choco install jq
- choco install curl
Expand Down
13 changes: 0 additions & 13 deletions bower.json

This file was deleted.

1 change: 0 additions & 1 deletion docs/RUNNING-LOCALLY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Prerequisites
### Common

- [NodeJS](https://nodejs.org) (at least v6)
- [Bower](http://bower.io)
- [Python](https://www.python.org)
- [jq](https://stedolan.github.io/jq/)
- [Asar](https://github.com/electron/asar)
Expand Down
11 changes: 0 additions & 11 deletions lib/gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
<!-- See https://github.com/visionmedia/debug#browser-support -->
<script>window.localStorage.debug = '*';</script>

<script>
window._trackJs = {
token: '032448bc3d9e4cffb1e9b43d29d6c142',
application: 'etcher',
console: {
error: false
}
};
</script>
<script src="../../node_modules/trackjs/tracker.js"></script>

<script src="./app.js"></script>
</head>
<body ng-app="Etcher">
Expand Down
134 changes: 23 additions & 111 deletions lib/gui/modules/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,116 +20,54 @@
* @module Etcher.Modules.Analytics
*/

const _ = require('lodash');
const angular = require('angular');
const isRunningInAsar = require('electron-is-running-in-asar');
const errors = require('../../shared/errors');
const os = require('os');
const _ = require('lodash');
const resinCorvus = require('resin-corvus/browser');
const packageJSON = require('../../../package.json');
const arch = require('arch');
const utils = require('../../shared/utils');
const settings = require('../models/settings');

// Force Mixpanel snippet to load Mixpanel locally
// instead of using a CDN for performance reasons
window.MIXPANEL_CUSTOM_LIB_URL = '../../bower_components/mixpanel/mixpanel.js';

require('../../../bower_components/mixpanel/mixpanel-jslib-snippet.js');
require('../../../bower_components/angular-mixpanel/src/angular-mixpanel');
const MODULE_NAME = 'Etcher.Modules.Analytics';
const analytics = angular.module(MODULE_NAME, [
'analytics.mixpanel'
]);

/**
* @summary Get host architecture
* @function
* @private
*
* @description
* We need this because node's os.arch() returns the process architecture
* See: https://github.com/nodejs/node-v0.x-archive/issues/2862
*
* @returns {String} Host architecture
*
* @example
* if (getHostArchitecture() === 'x64') {
* console.log('Host architecture is x64');
* }
*/
const getHostArchitecture = () => {
return _.includes([ 'ia32', 'x64' ], process.arch) ? _.replace(arch(), 'x86', 'ia32') : process.arch;
};

// Mixpanel integration
// https://github.com/kuhnza/angular-mixpanel

analytics.config(($mixpanelProvider) => {
$mixpanelProvider.apiKey('63e5fc4563e00928da67d1226364dd4c');

$mixpanelProvider.superProperties({
electron: process.versions.electron,
node: process.version,
arch: process.arch,
version: packageJSON.version,
osPlatform: os.platform(),
hostArch: getHostArchitecture(),
osRelease: os.release(),
cpuCores: os.cpus().length,
totalMemory: os.totalmem(),
startFreeMemory: os.freemem()
});
});

// TrackJS integration
// http://docs.trackjs.com/tracker/framework-integrations

analytics.run(($window) => {

// Don't configure TrackJS when
// running inside the test suite
if (window.mocha) {
return;
}

$window.trackJs.configure({
userId: os.userInfo().username,
version: packageJSON.version
const analytics = angular.module(MODULE_NAME, []);

analytics.run(() => {
resinCorvus.install({
services: {
sentry: _.get(packageJSON, [ 'analytics', 'sentry', 'token' ]),
mixpanel: _.get(packageJSON, [ 'analytics', 'mixpanel', 'token' ])
},
options: {
release: packageJSON.version,
shouldReport: () => {
return settings.get('errorReporting');
}
}
});
});

analytics.service('AnalyticsService', function($log, $window, $mixpanel) {
analytics.service('AnalyticsService', function() {

/**
* @summary Log a debug message
* @function
* @public
*
* @description
* This function sends the debug message to TrackJS only.
* This function sends the debug message to error reporting services.
*
* @param {String} message - message
*
* @example
* AnalyticsService.log('Hello World');
*/
this.logDebug = (message) => {
const debugMessage = `${new Date()} ${message}`;

if (settings.get('errorReporting') && isRunningInAsar()) {
$window.trackJs.console.debug(debugMessage);
}

$log.debug(debugMessage);
};
this.logDebug = resinCorvus.logDebug;

/**
* @summary Log an event
* @function
* @public
*
* @description
* This function sends the debug message to TrackJS and Mixpanel.
* This function sends the debug message to product analytics services.
*
* @param {String} message - message
* @param {Object} [data] - event data
Expand All @@ -139,48 +77,22 @@ analytics.service('AnalyticsService', function($log, $window, $mixpanel) {
* image: '/dev/disk2'
* });
*/
this.logEvent = (message, data) => {
const debugData = utils.hideAbsolutePathsInObject(utils.makeFlatStartCaseObject(data));

if (settings.get('errorReporting') && isRunningInAsar()) {
$mixpanel.track(message, debugData);
}

const debugMessage = _.attempt(() => {
if (debugData) {
return `${message} (${JSON.stringify(debugData)})`;
}

return message;
});

this.logDebug(debugMessage);
};
this.logEvent = resinCorvus.logEvent;

/**
* @summary Log an exception
* @function
* @public
*
* @description
* This function logs an exception in TrackJS.
* This function logs an exception to error reporting services.
*
* @param {Error} exception - exception
*
* @example
* AnalyticsService.logException(new Error('Something happened'));
*/
this.logException = (exception) => {
if (_.every([
settings.get('errorReporting'),
isRunningInAsar(),
errors.shouldReport(exception)
])) {
$window.trackJs.track(exception);
}

$log.error(exception);
};
this.logException = resinCorvus.logException;

});

Expand Down
23 changes: 0 additions & 23 deletions lib/shared/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,6 @@ const getUserFriendlyMessageProperty = (error, property) => {
return _.invoke(exports.HUMAN_FRIENDLY, [ code, property ], error);
};

/**
* @summary Check whether an error should be reported to TrackJS
* @function
* @public
*
* @description
* In order to determine whether the error should be reported, we
* check a property called `report`. For backwards compatibility, and
* to properly handle errors that we don't control, an error without
* this property is reported automatically.
*
* @param {Error} error - error
* @returns {Boolean} whether the error should be reported
*
* @example
* if (errors.shouldReport(new Error('foo'))) {
* console.log('We should report this error');
* }
*/
exports.shouldReport = (error) => {
return !_.has(error, [ 'report' ]) || Boolean(error.report);
};

/**
* @summary Check if a string is blank
* @function
Expand Down
Loading

0 comments on commit c4053c1

Please sign in to comment.