events: Report supervisor version with any mixpanel events

Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-09-02 16:35:46 -07:00
parent 607c722b0b
commit 8ca42062a3
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
2 changed files with 13 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import * as memoizee from 'memoizee';
import Mixpanel = require('mixpanel');
import supervisorVersion = require('./lib/supervisor-version');
export type EventTrackProperties = Dictionary<any>;
interface InitArgs {
@ -49,6 +51,7 @@ export class EventTracker {
this.defaultProperties = {
distinct_id: uuid,
uuid,
supervisorVersion,
};
if (offlineMode) {
return;

View File

@ -4,6 +4,8 @@ m = require 'mochainon'
{ expect } = m.chai
{ stub } = m.sinon
supervisorVersion = require '../src/lib/supervisor-version'
{ EventTracker } = require '../src/event-tracker'
describe 'EventTracker', ->
before ->
@ -48,7 +50,12 @@ describe 'EventTracker', ->
it 'calls the mixpanel client track function with the event, properties and uuid as distinct_id', ->
@eventTracker.track('Test event 2', { appId: 'someOtherValue' })
expect(@eventTracker.logEvent).to.be.calledWith('Event:', 'Test event 2', JSON.stringify({ appId: 'someOtherValue' }))
expect(@eventTracker.client.track).to.be.calledWith('Test event 2', { appId: 'someOtherValue', uuid: 'barbaz', distinct_id: 'barbaz' })
expect(@eventTracker.client.track).to.be.calledWith('Test event 2', {
appId: 'someOtherValue'
uuid: 'barbaz'
distinct_id: 'barbaz'
supervisorVersion
})
it 'can be passed an Error and it is added to the event properties', ->
theError = new Error('something went wrong')
@ -59,6 +66,7 @@ describe 'EventTracker', ->
stack: theError.stack
uuid: 'barbaz'
distinct_id: 'barbaz'
supervisorVersion
})
it 'hides service environment variables, to avoid logging keys or secrets', ->
@ -76,6 +84,7 @@ describe 'EventTracker', ->
service: { appId: '1' }
uuid: 'barbaz'
distinct_id: 'barbaz'
supervisorVersion
})
describe 'Rate limiting', ->