1
>
/*---------------------------------------------------------------------------------------------
telemetryUtils.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { cloneAndChange, safeStringify } from '../../../base/common/objects.js';
7
>
import { isObject } from '../../../base/common/types.js';
8
>
import { URI } from '../../../base/common/uri.js';
9
>
import { localize } from '../../../nls.js';
10
>
import { IConfigurationService } from '../../configuration/common/configuration.js';
11
>
import { IEnvironmentService } from '../../environment/common/environment.js';
12
>
import { LoggerGroup } from '../../log/common/log.js';
13
>
import { IProductService } from '../../product/common/productService.js';
14
>
import { getRemoteName } from '../../remote/common/remoteHosts.js';
15
>
import { verifyMicrosoftInternalDomain } from './commonProperties.js';
16
>
import { ICustomEndpointTelemetryService, ITelemetryData, ITelemetryEndpoint, ITelemetryService, TelemetryConfiguration, TelemetryLevel, TELEMETRY_CRASH_REPORTER_SETTING_ID, TELEMETRY_OLD_SETTING_ID, TELEMETRY_SETTING_ID } from './telemetry.js';
17
>
18
>
/**
19
>
* A special class used to denoting a telemetry value which should not be clean.
20
>
* This is because that value is "Trusted" not to contain identifiable information such as paths.
21
>
* NOTE: This is used as an API type as well, and should not be changed.
22
>
*/
23
>
export class TelemetryTrustedValue<T> {
24
>
// This is merely used as an identifier as the instance will be lost during serialization over the exthost
25
>
public readonly isTrustedTelemetryValue = true;
26
>
constructor(public readonly value: T) { }
27
>
}
28
>
29
>
export class NullTelemetryServiceShape implements ITelemetryService {
30
>
declare readonly _serviceBrand: undefined;
31
>
readonly telemetryLevel = TelemetryLevel.NONE;
32
>
readonly sessionId = 'someValue.sessionId';
33
>
readonly machineId = 'someValue.machineId';
34
>
readonly sqmId = 'someValue.sqmId';
35
>
readonly devDeviceId = 'someValue.devDeviceId';
36
>
readonly firstSessionDate = 'someValue.firstSessionDate';
37
>
readonly sendErrorTelemetry = false;
38
>
publicLog() { }
39
>
publicLog2() { }
40
>
publicLogError() { }
41
>
publicLogError2() { }
42
>
setExperimentProperty() { }
43
>
setCommonProperty() { }
44
>
}
45
>
46
>
export const NullTelemetryService = new NullTelemetryServiceShape();
47
>
48
>
export class NullEndpointTelemetryService implements ICustomEndpointTelemetryService {
49
>
_serviceBrand: undefined;
50
>
51
>
async publicLog(_endpoint: ITelemetryEndpoint, _eventName: string, _data?: ITelemetryData): Promise<void> {
52
// noop
53
}
55
>
async publicLogError(_endpoint: ITelemetryEndpoint, _errorEventName: string, _data?: ITelemetryData): Promise<void> {
56
// noop
57
}
59
>
60
>
export const telemetryLogId = 'telemetry';
61
>
export const TelemetryLogGroup: LoggerGroup = { id: telemetryLogId, name: localize('telemetryLogName', "Telemetry") };
62
>
63
>
export interface ITelemetryAppender {
64
>
log(eventName: string, data: ITelemetryData): void;
65
>
flush(): Promise<void>;
66
>
}
67
>
68
>
export const NullAppender: ITelemetryAppender = { log: () => null, flush: () => Promise.resolve(undefined) };
69
>
70
>
71
>
/* __GDPR__FRAGMENT__
72
>
"URIDescriptor" : {
73
>
"mimeType" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
74
>
"scheme": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
75
>
"ext": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
76
>
"path": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
77
>
}
78
>
*/
79
>
export interface URIDescriptor {
80
>
mimeType?: string;
81
>
scheme?: string;
82
>
ext?: string;
83
>
path?: string;
84
>
}
85
>
86
>
/**
87
>
* Determines whether or not we support logging telemetry.
88
>
* This checks if the product is capable of collecting telemetry but not whether or not it can send it
89
>
* For checking the user setting and what telemetry you can send please check `getTelemetryLevel`.
90
>
* This returns true if `--disable-telemetry` wasn't used, the product.json allows for telemetry, and we're not testing an extension
91
>
* If false telemetry is disabled throughout the product
92
>
* @param productService
93
>
* @param environmentService
94
>
* @returns false - telemetry is completely disabled, true - telemetry is logged locally, but may not be sent
95
>
*/
96
>
export function supportsTelemetry(productService: IProductService, environmentService: IEnvironmentService): boolean {
97
// If it's OSS and telemetry isn't disabled via the CLI we will allow it for logging only purposes
98
if (!environmentService.isBuilt && !environmentService.disableTelemetry) {