import * as util from 'util' ; import TelemetryReporter from 'vscode-extension-telemetry' ; const EXTENSION_NAME = 'salesforcedx-vscode-apex-debugger' ; export class TelemetryService { private static instance : TelemetryService ; private reporter : TelemetryReporter | undefined ; private isTelemetryEnabled : boolean ; constructor ( ) { this . isTelemetryEnabled = false ; } public static getInstance ( ) { if ( ! TelemetryService . instance ) { TelemetryService . instance = new TelemetryService ( ) ; } return TelemetryService . instance ; } public initializeService ( reporter , isTelemetryEnabled ) { this . isTelemetryEnabled = isTelemetryEnabled ; this . reporter = reporter ; } public sendExtensionActivationEvent ( hrstart ) { if ( this . reporter !== undefined && this . isTelemetryEnabled ) { const startupTime = this . getEndHRTime ( hrstart ) ; this . reporter . sendTelemetryEvent ( 'activationEvent' , { extensionName : EXTENSION_NAME , startupTime } ) ; } } public sendExtensionDeactivationEvent ( ) { if ( this . reporter !== undefined && this . isTelemetryEnabled ) { this . reporter . sendTelemetryEvent ( 'deactivationEvent' , { extensionName : EXTENSION_NAME } ) ; } } private getEndHRTime ( hrstart ) { const hrend = process . hrtime ( hrstart ) ; return util . format ( '%d%d' , hrend [ 0 ] , hrend [ 1 ] / 1000000 ) ; } }