Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,47 +2,32 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as appInsights from 'applicationinsights';
import { isObject } from 'vs/base/common/types';
import { safeStringify, mixin } from 'vs/base/common/objects';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITelemetryAppender } from 'vs/platform/telemetry/common/telemetryUtils';
import { ILogService } from 'vs/platform/log/common/log';
let _initialized = false;
function getClient(aiKey: string): appInsights.TelemetryClient {
function ensureAIEngineIsInitialized(): void {
if (_initialized === false) {
// we need to pass some fake key, otherwise AI throws an exception
appInsights.setup('2588e01f-f6c9-4cd6-a348-143741f8d702')
.setAutoCollectConsole(false)
.setAutoCollectExceptions(false)
let client: appInsights.TelemetryClient;
if (appInsights.defaultClient) {
client = new appInsights.TelemetryClient(aiKey);
client.channel.setUseDiskRetryCaching(true);
} else {
appInsights.setup(aiKey)
.setAutoCollectRequests(false)
.setAutoCollectPerformance(false)
.setAutoCollectRequests(false);
_initialized = true;
.setAutoCollectExceptions(false)
.setAutoCollectDependencies(false)
.setAutoDependencyCorrelation(false)
.setAutoCollectConsole(false)
.setInternalLogging(false, false)
.setUseDiskRetryCaching(true)
.start();
client = appInsights.defaultClient;
}
}
function getClient(aiKey: string): typeof appInsights.client {
ensureAIEngineIsInitialized();
const client = appInsights.getClient(aiKey);
client.channel.setOfflineMode(true);
// {{SQL CARBON EDIT}}
// clear all ID fields from telemetry
client.context.tags[client.context.keys.deviceMachineName] = '';
client.context.tags[client.context.keys.cloudRoleInstance] = '';
// set envelope flags to suppress Vortex ingest header
client.addTelemetryProcessor((envelope, contextObjects) => {
envelope.flags = 0x200000;
return true;
});
if (aiKey.indexOf('AIF-') === 0) {
client.config.endpointUrl = 'https://vortex.data.microsoft.com/collect/v1';
@@ -60,12 +45,12 @@ interface Measurements {
export class AppInsightsAppender implements ITelemetryAppender {
private _aiClient: typeof appInsights.client;
private _aiClient: appInsights.TelemetryClient;
constructor(
private _eventPrefix: string,
private _defaultData: { [key: string]: any },
aiKeyOrClientFactory: string | (() => typeof appInsights.client), // allow factory function for testing
aiKeyOrClientFactory: string | (() => appInsights.ITelemetryClient), // allow factory function for testing
@ILogService private _logService?: ILogService
) {
if (!this._defaultData) {
@@ -151,19 +136,25 @@ export class AppInsightsAppender implements ITelemetryAppender {
if (this._logService) {
this._logService.trace(`telemetry/${eventName}`, data);
}
this._aiClient.trackEvent(this._eventPrefix + '/' + eventName, data.properties, data.measurements);
this._aiClient.trackEvent({
name: this._eventPrefix + '/' + eventName,
properties: data.properties,
measurements: data.measurements
});
}
dispose(): TPromise<any> {
dispose(): Promise<any> {
if (this._aiClient) {
return new TPromise(resolve => {
this._aiClient.sendPendingData(() => {
// all data flushed
this._aiClient = undefined;
resolve(void 0);
return new Promise(resolve => {
this._aiClient.flush({
callback: () => {
// all data flushed
this._aiClient = undefined;
resolve(void 0);
}
});
});
}
return undefined;
}
}
}

View File

@@ -5,14 +5,13 @@
import * as Platform from 'vs/base/common/platform';
import * as os from 'os';
import { TPromise } from 'vs/base/common/winjs.base';
import * as uuid from 'vs/base/common/uuid';
import { readFile } from 'vs/base/node/pfs';
// {{SQL CARBON EDIT}}
import product from 'vs/platform/node/product';
export function resolveCommonProperties(commit: string, version: string, machineId: string, installSourcePath: string): TPromise<{ [name: string]: string; }> {
export function resolveCommonProperties(commit: string, version: string, machineId: string, installSourcePath: string): Promise<{ [name: string]: string; }> {
const result: { [name: string]: string; } = Object.create(null);
// {{SQL CARBON EDIT}}
@@ -30,7 +29,7 @@ export function resolveCommonProperties(commit: string, version: string, machine
// __GDPR__COMMON__ "common.platformVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platformVersion'] = (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
// __GDPR__COMMON__ "common.platform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platform'] = Platform.Platform[Platform.platform];
result['common.platform'] = Platform.PlatformToString(Platform.platform);
// __GDPR__COMMON__ "common.nodePlatform" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.nodePlatform'] = process.platform;
// __GDPR__COMMON__ "common.nodeArch" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
@@ -69,4 +68,4 @@ export function resolveCommonProperties(commit: string, version: string, machine
}, error => {
return result;
});
}
}

View File

@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
import { ITelemetryAppender } from 'vs/platform/telemetry/common/telemetryUtils';
import { Event } from 'vs/base/common/event';
export interface ITelemetryLog {
eventName: string;
data?: any;
}
export class TelemetryAppenderChannel implements IServerChannel {
constructor(private appender: ITelemetryAppender) { }
listen<T>(_, event: string): Event<T> {
throw new Error(`Event not found: ${event}`);
}
call(_, command: string, { eventName, data }: ITelemetryLog): Thenable<any> {
this.appender.log(eventName, data);
return Promise.resolve(null);
}
}
export class TelemetryAppenderClient implements ITelemetryAppender {
constructor(private channel: IChannel) { }
log(eventName: string, data?: any): any {
this.channel.call('log', { eventName, data })
.then(undefined, err => `Failed to log telemetry: ${console.warn(err)}`);
return Promise.resolve(null);
}
dispose(): any {
// TODO
}
}

View File

@@ -2,15 +2,14 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { URI } from 'vs/base/common/uri';
import product from 'vs/platform/node/product';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
export function addGAParameters(telemetryService: ITelemetryService, environmentService: IEnvironmentService, uri: URI, origin: string, experiment = '1'): TPromise<URI> {
export function addGAParameters(telemetryService: ITelemetryService, environmentService: IEnvironmentService, uri: URI, origin: string, experiment = '1'): Thenable<URI> {
if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !environmentService.args['disable-telemetry'] && !!product.enableTelemetry) {
if (uri.scheme === 'https' && uri.authority === 'code.visualstudio.com') {
return telemetryService.getTelemetryInfo()
@@ -19,5 +18,5 @@ export function addGAParameters(telemetryService: ITelemetryService, environment
});
}
}
return TPromise.as(uri);
return Promise.resolve(uri);
}

View File

@@ -3,43 +3,42 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import * as uuid from 'vs/base/common/uuid';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { resolveCommonProperties } from '../node/commonProperties';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
export const lastSessionDateStorageKey = 'telemetry.lastSessionDate';
// {{ SQL CARBON EDIT }}
import product from 'vs/platform/node/product';
import * as Utils from 'sql/common/telemetryUtilities';
export function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string, version: string, machineId: string, installSourcePath: string): TPromise<{ [name: string]: string }> {
export function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string, version: string, machineId: string, installSourcePath: string): Promise<{ [name: string]: string }> {
return resolveCommonProperties(commit, version, machineId, installSourcePath).then(result => {
// __GDPR__COMMON__ "common.version.shell" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.version.shell'] = process.versions && (<any>process).versions['electron'];
result['common.version.shell'] = process.versions && process.versions['electron'];
// __GDPR__COMMON__ "common.version.renderer" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.version.renderer'] = process.versions && (<any>process).versions['chrome'];
result['common.version.renderer'] = process.versions && process.versions['chrome'];
// {{SQL CARBON EDIT}}
result['common.application.name'] = product.nameLong;
// {{SQL CARBON EDIT}}
result['common.userId'] = '';
// {{SQL CARBON EDIT}}
// const lastSessionDate = storageService.get('telemetry.lastSessionDate');
// const firstSessionDate = storageService.get('telemetry.firstSessionDate') || new Date().toUTCString();
// storageService.store('telemetry.firstSessionDate', firstSessionDate);
// storageService.store('telemetry.lastSessionDate', new Date().toUTCString());
// // __GDPR__COMMON__ "common.firstSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.firstSessionDate'] = firstSessionDate;
// // __GDPR__COMMON__ "common.lastSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.lastSessionDate'] = lastSessionDate;
// // __GDPR__COMMON__ "common.isNewSession" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.isNewSession'] = !lastSessionDate ? '1' : '0';
// const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL);
// if (!process.env['VSCODE_TEST_STORAGE_MIGRATION']) {
// storageService.store(lastSessionDateStorageKey, new Date().toUTCString(), StorageScope.GLOBAL);
// }
// {{SQL CARBON EDIT}}
// __GDPR__COMMON__ "common.instanceId" : { "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
// // __GDPR__COMMON__ "common.firstSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.firstSessionDate'] = getOrCreateFirstSessionDate(storageService);
// // __GDPR__COMMON__ "common.lastSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.lastSessionDate'] = lastSessionDate || '';
// // __GDPR__COMMON__ "common.isNewSession" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.isNewSession'] = !lastSessionDate ? '1' : '0';
// // __GDPR__COMMON__ "common.instanceId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.instanceId'] = getOrCreateInstanceId(storageService);
result['common.instanceId'] = '';
// {{SQL CARBON EDIT}}
setUsageDates(storageService);
@@ -49,24 +48,46 @@ export function resolveWorkbenchCommonProperties(storageService: IStorageService
// {{SQL CARBON EDIT}}
// function getOrCreateInstanceId(storageService: IStorageService): string {
// const result = storageService.get('telemetry.instanceId') || uuid.generateUuid();
// storageService.store('telemetry.instanceId', result);
// return result;
// const key = 'telemetry.instanceId';
// let instanceId = storageService.get(key, StorageScope.GLOBAL, void 0);
// if (instanceId) {
// return instanceId;
// }
// instanceId = uuid.generateUuid();
// storageService.store(key, instanceId, StorageScope.GLOBAL);
// return instanceId;
// }
function getOrCreateFirstSessionDate(storageService: IStorageService): string {
const key = 'telemetry.firstSessionDate';
let firstSessionDate = storageService.get(key, StorageScope.GLOBAL, void 0);
if (firstSessionDate) {
return firstSessionDate;
}
firstSessionDate = new Date().toUTCString();
storageService.store(key, firstSessionDate, StorageScope.GLOBAL);
return firstSessionDate;
}
// {{SQL CARBON EDIT}}
function setUsageDates(storageService: IStorageService): void {
// daily last usage date
const appStartDate = new Date('January 1, 2000');
const dailyLastUseDate = storageService.get('telemetry.dailyLastUseDate') || appStartDate;
storageService.store('telemetry.dailyLastUseDate', dailyLastUseDate);
const dailyLastUseDate = storageService.get('telemetry.dailyLastUseDate', StorageScope.GLOBAL) || appStartDate;
storageService.store('telemetry.dailyLastUseDate', dailyLastUseDate, StorageScope.GLOBAL);
// weekly last usage date
const weeklyLastUseDate = storageService.get('telemetry.weeklyLastUseDate') || appStartDate;
storageService.store('telemetry.weeklyLastUseDate', weeklyLastUseDate);
const weeklyLastUseDate = storageService.get('telemetry.weeklyLastUseDate', StorageScope.GLOBAL) || appStartDate;
storageService.store('telemetry.weeklyLastUseDate', weeklyLastUseDate, StorageScope.GLOBAL);
// monthly last usage date
const monthlyLastUseDate = storageService.get('telemetry.monthlyLastUseDate') || appStartDate;
storageService.store('telemetry.monthlyLastUseDate', monthlyLastUseDate);
const monthlyLastUseDate = storageService.get('telemetry.monthlyLastUseDate', StorageScope.GLOBAL) || appStartDate;
storageService.store('telemetry.monthlyLastUseDate', monthlyLastUseDate, StorageScope.GLOBAL);
}
}