'use strict' ; import TelemetryReporter from 'vscode-extension-telemetry' ; import { getExperimentationServiceAsync , IExperimentationService , IExperimentationTelemetry , TargetPopulation } from 'vscode-tas-client' ; import * as util from './common' ; interface IPackageInfo { name : string ; version : string ; } export class ExperimentationTelemetry implements IExperimentationTelemetry { private sharedProperties : Record < string , string > = { } ; constructor ( private baseReporter ) { } sendTelemetryEvent ( eventName , properties ? , measurements ? ) { this . baseReporter . sendTelemetryEvent ( eventName , { ... this . sharedProperties , ... properties } , measurements ) ; } sendTelemetryErrorEvent ( eventName , properties ? , _measurements ? ) { this . baseReporter . sendTelemetryErrorEvent ( eventName , { ... this . sharedProperties , ... properties } ) ; } setSharedProperty ( name , value ) { this . sharedProperties [ name ] = value ; } postEvent ( eventName , props ) { const event = { } ; for ( const [ key , value ] of props ) { event [ key ] = value ; } this . sendTelemetryEvent ( eventName , event ) ; } dispose ( ) { return this . baseReporter . dispose ( ) ; } } let initializationPromise ; let experimentationTelemetry ; const appInsightsKey = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217" ; export function activate ( ) { try { if ( util . extensionContext ) { const packageInfo = getPackageInfo ( ) ; if ( packageInfo ) { const targetPopulation = util . getCppToolsTargetPopulation ( ) ; experimentationTelemetry = new ExperimentationTelemetry ( new TelemetryReporter ( packageInfo . name , packageInfo . version , appInsightsKey ) ) ; initializationPromise = getExperimentationServiceAsync ( packageInfo . name , packageInfo . version , targetPopulation , experimentationTelemetry , util . extensionContext . globalState ) ; } } } catch ( e ) { } } export function getExperimentationService ( ) { return initializationPromise ; } export async function deactivate ( ) { if ( initializationPromise ) { try { await initializationPromise ; } catch ( e ) { } } if ( experimentationTelemetry ) { experimentationTelemetry . dispose ( ) ; } } export function logDebuggerEvent ( eventName , properties ? ) { const sendTelemetry = ( ) => { if ( experimentationTelemetry ) { const eventNamePrefix = "cppdbg/VS/Diagnostics/Debugger/" ; experimentationTelemetry . sendTelemetryEvent ( eventNamePrefix + eventName , properties ) ; } } ; if ( initializationPromise ) { try { initializationPromise . then ( sendTelemetry ) ; return ; } catch ( e ) { } } sendTelemetry ( ) ; } export function logLanguageServerEvent ( eventName , properties ? , metrics ? ) { const sendTelemetry = ( ) => { if ( experimentationTelemetry ) { const eventNamePrefix = "C_Cpp/LanguageServer/" ; experimentationTelemetry . sendTelemetryEvent ( eventNamePrefix + eventName , properties , metrics ) ; } } ; if ( initializationPromise ) { try { initializationPromise . then ( sendTelemetry ) ; return ; } catch ( e ) { } } sendTelemetry ( ) ; } function getPackageInfo ( ) { return { name : util . packageJson . publisher + "." + util . packageJson . name , version : util . packageJson . version } ; }