import { ObjectMap } from './utils/collections' ; import * as fs from 'fs' ; export interface VsTelemetryReporterLike { sendTelemetryEvent ( eventName , properties ? , measurements ? ) : void ; dispose ( ) : Promise < any > ; } export class TelemetryReporterLocator { private static telemetryReporter : TelemetryReporter ; static load ( packageConfPath , reporterCreator ) { const packageInfo = JSON . parse ( fs . readFileSync ( packageConfPath , 'utf8' ) ) ; const extensionId = `${ packageInfo . publisher }.${ packageInfo . name }` ; const extensionVersion = packageInfo . version ; const key = packageInfo . telemetryKey ; const vsTelemetryReporter = reporterCreator ( extensionId , extensionVersion , key ) ; TelemetryReporterLocator . telemetryReporter = new TelemetryReporter ( vsTelemetryReporter ) ; } static getReporter ( ) { return TelemetryReporterLocator . telemetryReporter ; } } export class TelemetryReporter { constructor ( private readonly reporter ) { } logCommandTrigger ( commandName ) { this . reporter . sendTelemetryEvent ( 'commandTriggered' , { commandName } ) ; } logCommandErrored ( commandName ) { this . reporter . sendTelemetryEvent ( 'commandErrored' , { commandName } ) ; } dispose ( ) { return this . reporter . dispose ( ) ; } } export type VsTelemetryReporterCreator = ( extensionId : string , extensionVersion : string , telemetryKey : string ) => VsTelemetryReporterLike ; export class NullVsTelemetryReporter implements VsTelemetryReporterLike { sendTelemetryEvent ( _eventName , _properties ? , _measurements ? ) { } dispose ( ) { return Promise . resolve ( ) ; } }