@@ -8,14 +8,16 @@ import * as vscode from 'vscode';
88import * as child_process from 'child_process' ;
99import * as fs from 'fs' ;
1010import * as path from 'path' ;
11+ import TelemetryReporter from 'vscode-extension-telemetry' ;
1112
1213let _coreClrDebugDir : string ;
1314let _debugAdapterDir : string ;
1415let _channel : vscode . OutputChannel ;
1516let _installLog : NodeJS . WritableStream ;
17+ let _reporter : TelemetryReporter ; // Telemetry reporter
1618const _completionFileName : string = 'install.complete' ;
1719
18- export function installCoreClrDebug ( context : vscode . ExtensionContext ) {
20+ export function installCoreClrDebug ( context : vscode . ExtensionContext ) {
1921 _coreClrDebugDir = path . join ( context . extensionPath , 'coreclr-debug' ) ;
2022 _debugAdapterDir = path . join ( _coreClrDebugDir , 'debugAdapters' ) ;
2123
@@ -30,6 +32,7 @@ export function installCoreClrDebug(context: vscode.ExtensionContext) {
3032 return ;
3133 }
3234
35+ initializeTelemetry ( context ) ;
3336 _channel = vscode . window . createOutputChannel ( 'coreclr-debug' ) ;
3437
3538 // Create our log file and override _channel.append to also outpu to the log
@@ -45,34 +48,65 @@ export function installCoreClrDebug(context: vscode.ExtensionContext) {
4548 _channel . appendLine ( "Downloading and configuring the .NET Core Debugger..." ) ;
4649 _channel . show ( vscode . ViewColumn . Three ) ;
4750
51+ var installStage = 'dotnet restore' ;
52+ var installError = '' ;
53+
4854 spawnChildProcess ( 'dotnet' , [ '--verbose' , 'restore' , '--configfile' , 'NuGet.config' ] , _channel , _coreClrDebugDir )
4955 . then ( function ( ) {
56+ installStage = "dotnet publish" ;
5057 return spawnChildProcess ( 'dotnet' , [ '--verbose' , 'publish' , '-o' , _debugAdapterDir ] , _channel , _coreClrDebugDir ) ;
5158 } ) . then ( function ( ) {
59+ installStage = "ensureAd7" ;
5260 return ensureAd7EngineExists ( _channel , _debugAdapterDir ) ;
5361 } ) . then ( function ( ) {
62+ installStage = "additionalTasks"
5463 var promises : Promise < void > [ ] = [ ] ;
5564
5665 promises . push ( renameDummyEntrypoint ( ) ) ;
5766 promises . push ( removeLibCoreClrTraceProvider ( ) ) ;
5867
5968 return Promise . all ( promises ) ;
6069 } ) . then ( function ( ) {
70+ installStage = "writeCompletionFile" ;
6171 return writeCompletionFile ( ) ;
6272 } ) . then ( function ( ) {
73+ installStage = "completeSuccess" ;
6374 _channel . appendLine ( 'Succesfully installed .NET Core Debugger.' ) ;
6475 } )
6576 . catch ( function ( error ) {
6677 _channel . appendLine ( 'Error while installing .NET Core Debugger.' ) ;
78+
79+ installError = error . toString ( ) ;
6780 console . log ( error ) ;
81+ } ) . then ( function ( ) {
82+ // log telemetry
83+ logTelemetry ( 'Acquisition' , { installStage : installStage , installError : installError } ) ;
6884 } ) ;
6985}
7086
87+ function initializeTelemetry ( context : vscode . ExtensionContext ) {
88+ // parse our own package.json into json
89+ var packageJson = JSON . parse ( fs . readFileSync ( path . join ( context . extensionPath , 'package.json' ) ) . toString ( ) ) ;
90+
91+ let extensionId = packageJson [ "publisher" ] + "." + packageJson [ "name" ] ;
92+ let extensionVersion = packageJson [ "version" ] ;
93+ let aiKey = packageJson . contributes . debuggers [ 0 ] [ "aiKey" ] ;
94+
95+ _reporter = new TelemetryReporter ( extensionId , extensionVersion , aiKey ) ;
96+ }
97+
98+ function logTelemetry ( eventName : string , properties ?: { [ prop : string ] : string } ) {
99+ if ( _reporter )
100+ {
101+ _reporter . sendTelemetryEvent ( 'coreclr-debug/' + eventName , properties ) ;
102+ }
103+ }
104+
71105function writeCompletionFile ( ) : Promise < void > {
72106 return new Promise < void > ( function ( resolve , reject ) {
73107 fs . writeFile ( path . join ( _debugAdapterDir , _completionFileName ) , '' , function ( err ) {
74108 if ( err ) {
75- reject ( err ) ;
109+ reject ( err . code ) ;
76110 }
77111 else {
78112 resolve ( ) ;
@@ -91,7 +125,7 @@ function renameDummyEntrypoint() : Promise<void> {
91125 var promise = new Promise < void > ( function ( resolve , reject ) {
92126 fs . rename ( src , dest , function ( err ) {
93127 if ( err ) {
94- reject ( err ) ;
128+ reject ( err . code ) ;
95129 } else {
96130 resolve ( ) ;
97131 }
@@ -111,7 +145,7 @@ function removeLibCoreClrTraceProvider() : Promise<void>
111145 return new Promise < void > ( function ( resolve , reject ) {
112146 fs . unlink ( filePath , function ( err ) {
113147 if ( err ) {
114- reject ( err ) ;
148+ reject ( err . code ) ;
115149 } else {
116150 _channel . appendLine ( 'Succesfully deleted ' + filePath ) ;
117151 resolve ( ) ;
@@ -129,7 +163,7 @@ function existsSync(path: string) : boolean {
129163 if ( err . code === 'ENOENT' ) {
130164 return false ;
131165 } else {
132- throw err ;
166+ throw Error ( err . code ) ;
133167 }
134168 }
135169}
0 commit comments