balena-supervisor/src/event-tracker.ts
Felipe Lalanne e00687408c Disable event tracking
The supervisor used to rely on specific event reporting for identifying
issues at runtime. As the platform has grown, it has become much more
difficult to get any signal from the event noise. Recently the API side
for these events has been disabled, meaning these events only
contribute to bandwidth consumption.  This commit disables the
event reporting feature of the supervisor which will be most likely
replaced by something like Sentry in the near future.

Change-type: minor
2022-09-20 14:19:26 -03:00

40 lines
1019 B
TypeScript

import mask = require('json-mask');
import * as _ from 'lodash';
import log from './lib/supervisor-console';
export type EventTrackProperties = Dictionary<any>;
const mixpanelMask = [
'appId',
'delay',
'error',
'interval',
'image',
'app(appId,name)',
'service(appId,serviceId,serviceName,commit,releaseId,image,labels)',
'stateDiff/local(os_version,supervisor_version,ip_address,apps/*/services)',
].join(',');
export async function track(
event: string,
properties: EventTrackProperties | Error = {},
) {
if (properties instanceof Error) {
properties = { error: properties };
}
properties = _.cloneDeep(properties);
if (properties.error instanceof Error) {
// Format the error for printing, to avoid display as { }
properties.error = {
message: properties.error.message,
stack: properties.error.stack,
};
}
// Don't send potentially sensitive information, by using a whitelist
properties = mask(properties, mixpanelMask);
log.event('Event:', event, JSON.stringify(properties));
}