Merge pull request #1641 from balena-io/improve-events

Improve events
This commit is contained in:
Page- 2020-03-24 18:54:55 +00:00 committed by GitHub
commit c8275b52c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,10 +22,9 @@ import * as Mixpanel from 'mixpanel';
import * as packageJSON from '../package.json'; import * as packageJSON from '../package.json';
import { getBalenaSdk } from './utils/lazy'; import { getBalenaSdk } from './utils/lazy';
const getMixpanel = _.once<any>(() => { const getMixpanel = _.once((balenaUrl: string) => {
const settings = require('balena-settings-client');
return Mixpanel.init('balena-main', { return Mixpanel.init('balena-main', {
host: `api.${settings.get('balenaUrl')}`, host: `api.${balenaUrl}`,
path: '/mixpanel', path: '/mixpanel',
protocol: 'https', protocol: 'https',
}); });
@ -47,10 +46,11 @@ const getMixpanel = _.once<any>(() => {
*/ */
export function trackCommand(commandSignature: string) { export function trackCommand(commandSignature: string) {
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const balenaUrlPromise = balena.settings.get('balenaUrl');
return Bluebird.props({ return Bluebird.props({
balenaUrl: balena.settings.get('balenaUrl'), balenaUrl: balenaUrlPromise,
username: balena.auth.whoami().catchReturn(undefined), username: balena.auth.whoami().catchReturn(undefined),
mixpanel: getMixpanel(), mixpanel: balenaUrlPromise.then(getMixpanel),
}) })
.then(({ username, balenaUrl, mixpanel }) => { .then(({ username, balenaUrl, mixpanel }) => {
Sentry.configureScope(scope => { Sentry.configureScope(scope => {