33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import * as crypto from 'crypto' ;
7- import { machineIdSync } from 'node-machine-id' ;
86import { PlatformInformation } from '../shared/platform' ;
97import {
108 BaseEvent ,
@@ -20,25 +18,13 @@ import { PackageError } from '../packageManager/packageError';
2018import { EventType } from '../omnisharp/eventType' ;
2119import { getDotnetInfo } from '../shared/utils/getDotnetInfo' ;
2220import { DotnetInfo } from '../shared/utils/dotnetInfo' ;
23-
24- export interface ITelemetryReporter {
25- sendTelemetryEvent (
26- eventName : string ,
27- properties ?: { [ key : string ] : string } ,
28- measures ?: { [ key : string ] : number }
29- ) : void ;
30- sendTelemetryErrorEvent (
31- eventName : string ,
32- properties ?: { [ key : string ] : string } ,
33- measures ?: { [ key : string ] : number } ,
34- errorProps ?: string [ ]
35- ) : void ;
36- }
21+ import { ITelemetryReporter , getTelemetryProps } from '../shared/telemetryReporter' ;
22+ import { reportProjectConfigurationEvent } from '../shared/projectConfiguration' ;
3723
3824export class TelemetryObserver {
3925 private reporter : ITelemetryReporter ;
4026 private platformInfo : PlatformInformation ;
41- private solutionId ?: string ;
27+ private solutionPath ?: string ;
4228 private dotnetInfo ?: DotnetInfo ;
4329 private useModernNet : boolean ;
4430
@@ -49,7 +35,7 @@ export class TelemetryObserver {
4935 }
5036
5137 public post = ( event : BaseEvent ) => {
52- const telemetryProps = this . getTelemetryProps ( ) ;
38+ const telemetryProps = getTelemetryProps ( this . platformInfo ) ;
5339 switch ( event . type ) {
5440 case EventType . OmnisharpInitialisation :
5541 this . handleOmnisharpInitialisation ( < OmnisharpInitialisation > event ) ;
@@ -90,7 +76,7 @@ export class TelemetryObserver {
9076 break ;
9177 }
9278 case EventType . ProjectConfigurationReceived :
93- this . handleProjectConfigurationReceived ( < ProjectConfiguration > event , telemetryProps ) ;
79+ this . handleProjectConfigurationReceived ( < ProjectConfiguration > event ) ;
9480 break ;
9581 }
9682 } ;
@@ -101,7 +87,7 @@ export class TelemetryObserver {
10187
10288 private async handleOmnisharpInitialisation ( event : OmnisharpInitialisation ) {
10389 this . dotnetInfo = await getDotnetInfo ( event . dotNetCliPaths ) ;
104- this . solutionId = this . createSolutionId ( event . solutionPath ) ;
90+ this . solutionPath = event . solutionPath ;
10591 }
10692
10793 private handleInstallationSuccess ( telemetryProps : { [ key : string ] : string } ) {
@@ -129,45 +115,15 @@ export class TelemetryObserver {
129115 }
130116 }
131117
132- private handleProjectConfigurationReceived ( event : ProjectConfiguration , telemetryProps : { [ key : string ] : string } ) {
118+ private handleProjectConfigurationReceived ( event : ProjectConfiguration ) {
133119 const projectConfig = event . projectConfiguration ;
134- telemetryProps [ 'SolutionId' ] = this . solutionId ?? '' ;
135- telemetryProps [ 'ProjectId' ] = projectConfig . ProjectId ;
136- telemetryProps [ 'SessionId' ] = projectConfig . SessionId ;
137- telemetryProps [ 'OutputType' ] = projectConfig . OutputKind ?. toString ( ) ?? '' ;
138- telemetryProps [ 'ProjectCapabilities' ] = projectConfig . ProjectCapabilities ?. join ( ' ' ) ?? '' ;
139- telemetryProps [ 'TargetFrameworks' ] = projectConfig . TargetFrameworks . join ( '|' ) ;
140- telemetryProps [ 'References' ] = projectConfig . References . join ( '|' ) ;
141- telemetryProps [ 'FileExtensions' ] = projectConfig . FileExtensions . join ( '|' ) ;
142- telemetryProps [ 'FileCounts' ] = projectConfig . FileCounts ?. join ( '|' ) ?? '' ;
143- telemetryProps [ 'NetSdkVersion' ] = this . dotnetInfo ?. Version ?? '' ;
144- telemetryProps [ 'useModernNet' ] = this . useModernNet . toString ( ) ;
145- telemetryProps [ 'sdkStyleProject' ] = projectConfig . SdkStyleProject . toString ( ) ;
146- this . reporter . sendTelemetryEvent ( 'ProjectConfiguration' , telemetryProps ) ;
147- }
148-
149- private getTelemetryProps ( ) {
150- const telemetryProps : { [ key : string ] : string } = {
151- 'platform.architecture' : this . platformInfo . architecture ,
152- 'platform.platform' : this . platformInfo . platform ,
153- } ;
154-
155- if ( this . platformInfo . distribution ) {
156- telemetryProps [ 'platform.distribution' ] = this . platformInfo . distribution . toTelemetryString ( ) ;
157- }
158-
159- return telemetryProps ;
160- }
161-
162- private createSolutionId ( solutionPath : string ) {
163- const solutionHash = crypto . createHash ( 'sha256' ) . update ( solutionPath ) . digest ( 'hex' ) ;
164-
165- const machineId = machineIdSync ( ) ;
166- const machineHash = crypto . createHash ( 'sha256' ) . update ( machineId ) . digest ( 'hex' ) ;
167-
168- return crypto
169- . createHash ( 'sha256' )
170- . update ( solutionHash + machineHash )
171- . digest ( 'hex' ) ;
120+ reportProjectConfigurationEvent (
121+ this . reporter ,
122+ projectConfig ,
123+ this . platformInfo ,
124+ this . dotnetInfo ,
125+ this . solutionPath ?? '' ,
126+ this . useModernNet
127+ ) ;
172128 }
173129}
0 commit comments