Skip to content

Commit eccee07

Browse files
authored
Enable telemetry logging only in OSS (microsoft#166032)
* Enable telemetry logging only in OSS * Remove unnecessary comment * Update comment
1 parent 96bf637 commit eccee07

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

src/vs/platform/telemetry/common/telemetryUtils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,37 @@ export function configurationTelemetry(telemetryService: ITelemetryService, conf
113113
* @returns false - telemetry is completely disabled, true - telemetry is logged locally, but may not be sent
114114
*/
115115
export function supportsTelemetry(productService: IProductService, environmentService: IEnvironmentService): boolean {
116+
// If it's OSS and telemetry isn't disabled via the CLI we will allow it for logging only purposes
117+
if (!environmentService.isBuilt && !environmentService.disableTelemetry) {
118+
return true;
119+
}
116120
return !(environmentService.disableTelemetry || !productService.enableTelemetry || environmentService.extensionTestsLocationURI);
117121
}
118122

123+
/**
124+
* Checks to see if we're in logging only mode to debug telemetry.
125+
* This is if telemetry is enabled and we're in OSS, but no telemetry key is provided so it's not being sent just logged.
126+
* @param productService
127+
* @param environmentService
128+
* @returns True if telemetry is actually disabled and we're only logging for debug purposes
129+
*/
130+
export function isLoggingOnly(productService: IProductService, environmentService: IEnvironmentService): boolean {
131+
// Logging only mode is only for OSS
132+
if (environmentService.isBuilt) {
133+
return false;
134+
}
135+
136+
if (environmentService.disableTelemetry) {
137+
return false;
138+
}
139+
140+
if (productService.enableTelemetry && productService.aiConfig?.ariaKey) {
141+
return false;
142+
}
143+
144+
return true;
145+
}
146+
119147
/**
120148
* Determines how telemetry is handled based on the user's configuration.
121149
*

src/vs/workbench/api/browser/mainThreadTelemetry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
88
import { IProductService } from 'vs/platform/product/common/productService';
99
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
1010
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
11-
import { supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
11+
import { isLoggingOnly, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
1212
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
1313
import { ExtHostContext, ExtHostTelemetryShape, MainContext, MainThreadTelemetryShape } from '../common/extHost.protocol';
1414

@@ -33,8 +33,8 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
3333
this._proxy.$onDidChangeTelemetryLevel(level);
3434
}));
3535
}
36-
37-
this._proxy.$initializeTelemetryLevel(this.telemetryLevel, this._productService.enabledTelemetryLevels);
36+
const loggingOnly = isLoggingOnly(this._productService, this._environmentService);
37+
this._proxy.$initializeTelemetryLevel(this.telemetryLevel, loggingOnly, this._productService.enabledTelemetryLevels);
3838
}
3939

4040
private get telemetryLevel(): TelemetryLevel {

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ export interface ExtHostQuickOpenShape {
17901790
}
17911791

17921792
export interface ExtHostTelemetryShape {
1793-
$initializeTelemetryLevel(level: TelemetryLevel, productConfig?: { usage: boolean; error: boolean }): void;
1793+
$initializeTelemetryLevel(level: TelemetryLevel, debugLoggingOnly: boolean, productConfig?: { usage: boolean; error: boolean }): void;
17941794
$onDidChangeTelemetryLevel(level: TelemetryLevel): void;
17951795
}
17961796

src/vs/workbench/api/common/extHostTelemetry.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class ExtHostTelemetry implements ExtHostTelemetryShape {
2727
private _productConfig: { usage: boolean; error: boolean } = { usage: true, error: true };
2828
private _level: TelemetryLevel = TelemetryLevel.NONE;
2929
private _oldTelemetryEnablement: boolean | undefined;
30+
private _inLoggingOnlyMode: boolean = false;
3031
private readonly _outputLogger: ILogger;
3132
private readonly _telemetryLoggers = new Map<string, ExtHostTelemetryLogger>();
3233

@@ -53,14 +54,22 @@ export class ExtHostTelemetry implements ExtHostTelemetryShape {
5354

5455
instantiateLogger(extension: IExtensionDescription, appender: vscode.TelemetryAppender) {
5556
const telemetryDetails = this.getTelemetryDetails();
56-
const logger = new ExtHostTelemetryLogger(appender, extension, this._outputLogger, this.getBuiltInCommonProperties(extension), { isUsageEnabled: telemetryDetails.isUsageEnabled, isErrorsEnabled: telemetryDetails.isErrorsEnabled });
57+
const logger = new ExtHostTelemetryLogger(
58+
appender,
59+
extension,
60+
this._outputLogger,
61+
this._inLoggingOnlyMode,
62+
this.getBuiltInCommonProperties(extension),
63+
{ isUsageEnabled: telemetryDetails.isUsageEnabled, isErrorsEnabled: telemetryDetails.isErrorsEnabled }
64+
);
5765
this._telemetryLoggers.set(extension.identifier.value, logger);
5866
return logger.apiTelemetryLogger;
5967
}
6068

61-
$initializeTelemetryLevel(level: TelemetryLevel, productConfig?: { usage: boolean; error: boolean }): void {
69+
$initializeTelemetryLevel(level: TelemetryLevel, loggingOnlyMode: boolean, productConfig?: { usage: boolean; error: boolean }): void {
6270
this._level = level;
63-
this._productConfig = productConfig || { usage: true, error: true };
71+
this._inLoggingOnlyMode = loggingOnlyMode;
72+
this._productConfig = productConfig ?? { usage: true, error: true };
6473
}
6574

6675
getBuiltInCommonProperties(extension: IExtensionDescription): Record<string, string | boolean | number | undefined> {
@@ -126,8 +135,10 @@ export class ExtHostTelemetryLogger {
126135
appender: vscode.TelemetryAppender,
127136
private readonly _extension: IExtensionDescription,
128137
private readonly _logger: ILogger,
138+
private readonly _inLoggingOnlyMode: boolean,
129139
private readonly _commonProperties: Record<string, any>,
130-
telemetryEnablements: { isUsageEnabled: boolean; isErrorsEnabled: boolean }) {
140+
telemetryEnablements: { isUsageEnabled: boolean; isErrorsEnabled: boolean }
141+
) {
131142
this._appender = appender;
132143
this._telemetryEnablements = { isUsageEnabled: telemetryEnablements.isUsageEnabled, isErrorsEnabled: telemetryEnablements.isErrorsEnabled };
133144
}
@@ -173,7 +184,9 @@ export class ExtHostTelemetryLogger {
173184
eventName = this._extension.identifier.value + '/' + eventName;
174185
}
175186
data = this.mixInCommonPropsAndCleanData(data || {});
176-
this._appender.logEvent(eventName, data);
187+
if (!this._inLoggingOnlyMode) {
188+
this._appender.logEvent(eventName, data);
189+
}
177190
this._logger.trace(eventName, data);
178191
}
179192

src/vs/workbench/api/test/browser/extHostTelemetry.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ suite('ExtHostTelemetry', function () {
6868
override telemetryInfo: ITelemetryInfo = mockTelemetryInfo;
6969
override remote = mockRemote;
7070
}, new TestTelemetryLoggerService(DEFAULT_LOG_LEVEL));
71-
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, { usage: true, error: true });
71+
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, false, { usage: true, error: true });
7272
return extensionTelemetry;
7373
};
7474

@@ -100,19 +100,19 @@ suite('ExtHostTelemetry', function () {
100100
assert.strictEqual(config.isErrorsEnabled, true);
101101

102102
// Initialize would never be called twice, but this is just for testing
103-
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.ERROR, { usage: true, error: true });
103+
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.ERROR, false, { usage: true, error: true });
104104
config = extensionTelemetry.getTelemetryDetails();
105105
assert.strictEqual(config.isCrashEnabled, true);
106106
assert.strictEqual(config.isUsageEnabled, false);
107107
assert.strictEqual(config.isErrorsEnabled, true);
108108

109-
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.CRASH, { usage: true, error: true });
109+
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.CRASH, false, { usage: true, error: true });
110110
config = extensionTelemetry.getTelemetryDetails();
111111
assert.strictEqual(config.isCrashEnabled, true);
112112
assert.strictEqual(config.isUsageEnabled, false);
113113
assert.strictEqual(config.isErrorsEnabled, false);
114114

115-
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, { usage: false, error: true });
115+
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, false, { usage: false, error: true });
116116
config = extensionTelemetry.getTelemetryDetails();
117117
assert.strictEqual(config.isCrashEnabled, true);
118118
assert.strictEqual(config.isUsageEnabled, false);
@@ -181,7 +181,7 @@ suite('ExtHostTelemetry', function () {
181181
override telemetryInfo: ITelemetryInfo = mockTelemetryInfo;
182182
override remote = mockRemote;
183183
}, loggerService);
184-
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, { usage: true, error: true });
184+
extensionTelemetry.$initializeTelemetryLevel(TelemetryLevel.USAGE, false, { usage: true, error: true });
185185

186186
const functionSpy: TelemetryLoggerSpy = { dataArr: [], exceptionArr: [], flushCalled: false };
187187

src/vs/workbench/contrib/logs/common/logs.contribution.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
1717
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
1818
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
1919
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
20-
import { supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
20+
import { isLoggingOnly, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
2121
import { IProductService } from 'vs/platform/product/common/productService';
2222
import { URI } from 'vs/base/common/uri';
2323

@@ -55,8 +55,11 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
5555

5656
const registerTelemetryChannel = () => {
5757
if (supportsTelemetry(this.productService, this.environmentService) && this.logService.getLevel() === LogLevel.Trace) {
58-
this.registerLogChannel(Constants.telemetryLogChannelId, nls.localize('telemetryLog', "Telemetry"), this.environmentService.telemetryLogResource);
59-
this.registerLogChannel(Constants.extensionTelemetryLogChannelId, nls.localize('extensionTelemetryLog', "Extension Telemetry"), this.environmentService.extHostTelemetryLogFile);
58+
// Not a perfect check, but a nice way to indicate if we only have logging enabled for debug purposes and nothing is actually being sent
59+
const justLoggingAndNotSending = isLoggingOnly(this.productService, this.environmentService);
60+
const logSuffix = justLoggingAndNotSending ? ' (Logging Only)' : '';
61+
this.registerLogChannel(Constants.telemetryLogChannelId, nls.localize('telemetryLog', "Telemetry{0}", logSuffix), this.environmentService.telemetryLogResource);
62+
this.registerLogChannel(Constants.extensionTelemetryLogChannelId, nls.localize('extensionTelemetryLog', "Extension Telemetry{0}", logSuffix), this.environmentService.extHostTelemetryLogFile);
6063
return true;
6164
}
6265
return false;

0 commit comments

Comments
 (0)