@@ -9,7 +9,7 @@ import { Analytics, AnalyticsSettings } from '@segment/analytics-node';
99import { Disposable } from '../common/dispose' ;
1010import { Configuration } from '../configuration' ;
1111import { ILogService } from './logService' ;
12- import { cloneAndChange , escapeRegExpCharacters } from '../common/utils' ;
12+ import { cloneAndChange , escapeRegExpCharacters , mixin } from '../common/utils' ;
1313
1414const ProductionUntrustedSegmentKey = 'untrusted-dummy-key' ;
1515
@@ -48,7 +48,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
4848 private analitycsClients : Map < string , Analytics > = new Map ( ) ;
4949 private telemetryLogger : vscode . TelemetryLogger ;
5050
51- constructor ( segmentKey : string , piiPaths : string [ ] , private readonly logService : ILogService ) {
51+ constructor ( extensionId : string , extensionVersion : string , segmentKey : string , piiPaths : string [ ] , private readonly logService : ILogService ) {
5252 super ( ) ;
5353
5454 // static cleanup pattern for: `vscode-file:///DANGEROUS/PATH/resources/app/Useful/Information`
@@ -65,6 +65,8 @@ export class TelemetryService extends Disposable implements ITelemetryService {
6565 }
6666 }
6767
68+ const commonProperties = getCommonProperties ( extensionId , extensionVersion ) ;
69+
6870 this . telemetryLogger = this . _register ( vscode . env . createTelemetryLogger (
6971 {
7072 sendEventData : ( eventName , data ) => {
@@ -92,15 +94,16 @@ export class TelemetryService extends Disposable implements ITelemetryService {
9294 } ) ;
9395 } ,
9496 sendErrorData : ( error , data ) => {
95- const properties = cleanData ( data ?? { } , cleanupPatterns ) ;
96- const errorProps = cleanData ( { stack : error . stack } , cleanupPatterns ) ;
97+ let properties = cleanData ( data ?? { } , cleanupPatterns ) ;
98+ properties = mixin ( properties , commonProperties ) ;
99+ const errorProps = cleanData ( { message : error . message , stack : error . stack } , cleanupPatterns ) ;
97100
98101 // Unhandled errors have no data so use host from config
99102 const gitpodHost = properties [ 'gitpodHost' ] ?? Configuration . getGitpodHost ( ) ;
100103 const errorMetricsEndpoint = this . getErrorMetricsEndpoint ( gitpodHost ) ;
101104
102105 properties [ 'error_name' ] = error . name ;
103- properties [ 'error_message' ] = error . message ;
106+ properties [ 'error_message' ] = errorProps . message ;
104107 properties [ 'debug_workspace' ] = String ( properties [ 'debug_workspace' ] ?? false ) ;
105108
106109 const workspaceId = properties [ 'workspaceId' ] ?? '' ;
@@ -114,7 +117,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
114117
115118 const jsonData = {
116119 component : 'vscode-desktop-extension' ,
117- errorStack : errorProps . stack || String ( error ) ,
120+ errorStack : errorProps . stack || '' ,
118121 version : properties [ 'common.extversion' ] ,
119122 workspaceId,
120123 instanceId,
@@ -215,6 +218,33 @@ export class TelemetryService extends Disposable implements ITelemetryService {
215218// Remove when upstream TODO is addressed
216219// https://github.com/microsoft/vscode/blob/44ef5cc53127cbaa11dee1728bdf8c24522f8fa0/src/vs/workbench/api/common/extHostTelemetry.ts#L278-L279
217220
221+ function getCommonProperties ( extensionId : string , extensionVersion : string ) {
222+ const commonProperties = Object . create ( null ) ;
223+ commonProperties [ 'common.os' ] = os . platform ( ) ;
224+ commonProperties [ 'common.nodeArch' ] = os . arch ( ) ;
225+ commonProperties [ 'common.platformversion' ] = os . release ( ) . replace ( / ^ ( \d + ) ( \. \d + ) ? ( \. \d + ) ? ( .* ) / , '$1$2$3' ) ;
226+ commonProperties [ 'common.extname' ] = extensionId ;
227+ commonProperties [ 'common.extversion' ] = extensionVersion ;
228+ if ( vscode && vscode . env ) {
229+ commonProperties [ 'common.vscodemachineid' ] = vscode . env . machineId ;
230+ commonProperties [ 'common.vscodesessionid' ] = vscode . env . sessionId ;
231+ commonProperties [ 'common.vscodeversion' ] = vscode . version ;
232+ commonProperties [ 'common.product' ] = vscode . env . appHost ;
233+
234+ switch ( vscode . env . uiKind ) {
235+ case vscode . UIKind . Web :
236+ commonProperties [ 'common.uikind' ] = 'web' ;
237+ break ;
238+ case vscode . UIKind . Desktop :
239+ commonProperties [ 'common.uikind' ] = 'desktop' ;
240+ break ;
241+ default :
242+ commonProperties [ 'common.uikind' ] = 'unknown' ;
243+ }
244+ }
245+ return commonProperties ;
246+ }
247+
218248function anonymizeFilePaths ( stack : string , cleanupPatterns : RegExp [ ] ) : string {
219249
220250 // Fast check to see if it is a file path to avoid doing unnecessary heavy regex work
0 commit comments