Skip to content

Commit 8000435

Browse files
authored
Add TrustedTelemetryValue to API (microsoft#166620)
* Add TrustedTelemetryValue to API * Fix missing any * Address comments
1 parent 2fe850b commit 8000435

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } fro
1616
import { ICustomEndpointTelemetryService, ITelemetryData, ITelemetryEndpoint, ITelemetryInfo, ITelemetryService, TelemetryConfiguration, TelemetryLevel, TELEMETRY_OLD_SETTING_ID, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
1717

1818
/**
19-
* A special class used to denoate a telemetry value which should not be clean.
20-
* This is because that value is "Trusted" not to contain identifiable information such as paths
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.
2122
*/
22-
export class TrustedTelemetryValue {
23-
constructor(public readonly value: any) { }
23+
export class TrustedTelemetryValue<T> {
24+
constructor(public readonly value: T) { }
2425
}
2526

2627
export class NullTelemetryServiceShape implements ITelemetryService {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors';
4343
import { ExtHostTreeViews } from 'vs/workbench/api/common/extHostTreeViews';
4444
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
4545
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
46+
import { TrustedTelemetryValue } from 'vs/platform/telemetry/common/telemetryUtils';
4647
import { ExtHostUrls } from 'vs/workbench/api/common/extHostUrls';
4748
import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview';
4849
import { IExtHostWindow } from 'vs/workbench/api/common/extHostWindow';
@@ -1378,6 +1379,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
13781379
TabInputWebview: extHostTypes.WebviewEditorTabInput,
13791380
TabInputTerminal: extHostTypes.TerminalEditorTabInput,
13801381
TabInputInteractiveWindow: extHostTypes.InteractiveWindowInput,
1382+
TrustedTelemetryValue: TrustedTelemetryValue,
13811383
TerminalExitReason: extHostTypes.TerminalExitReason,
13821384
LogLevel: LogLevel,
13831385
EditSessionIdentityMatch: EditSessionIdentityMatch

src/vs/workbench/contrib/telemetry/browser/telemetry.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ViewContainerLocation } from 'vs/workbench/common/views';
2828
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
2929

3030
type TelemetryData = {
31-
mimeType: TrustedTelemetryValue;
31+
mimeType: TrustedTelemetryValue<string>;
3232
ext: string;
3333
path: number;
3434
reason?: number;

src/vs/workbench/services/timer/browser/timerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ export abstract class AbstractTimerService implements ITimerService {
584584
// event and it is "normalized" to a relative timestamp where the first mark
585585
// defines the start
586586

587-
type Mark = { source: string; name: TrustedTelemetryValue; startTime: number };
587+
type Mark = { source: string; name: TrustedTelemetryValue<string>; startTime: number };
588588
type MarkClassification = {
589589
owner: 'jrieken';
590590
comment: 'Information about a performance marker';

src/vscode-dts/vscode.proposed.telemetryLogger.d.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
declare module 'vscode' {
77

8+
/**
9+
* A special value wrapper denoting a value that is safe to not clean.
10+
* This is to be used when you can guarantee no identifiable information is contained in the value and the cleaning is improperly redacting it.
11+
*/
12+
export class TrustedTelemetryValue<T = any> {
13+
readonly value: T;
14+
constructor(value: T);
15+
}
16+
817
export interface TelemetryLogger {
918
//TODO feels weird having this on all loggers
1019
readonly onDidChangeEnableStates: Event<TelemetryLogger>;
@@ -17,15 +26,15 @@ declare module 'vscode' {
1726
* @param eventName The event name to log
1827
* @param data The data to log
1928
*/
20-
logUsage(eventName: string, data?: Record<string, string | number | boolean>): void;
29+
logUsage(eventName: string, data?: Record<string, any | TrustedTelemetryValue>): void;
2130

2231
/**
2332
* After completing cleaning, telemetry setting checks, and data mix-in calls `TelemetryAppender.logEvent` to log the event. Differs from `logUsage` in that it will log the event if the telemetry setting is Error+.
2433
* Automatically supports echoing to extension telemetry output channel.
2534
* @param eventName The event name to log
2635
* @param data The data to log
2736
*/
28-
logError(eventName: string, data?: Record<string, any>): void;
37+
logError(eventName: string, data?: Record<string, any | TrustedTelemetryValue>): void;
2938

3039
/**
3140
* Calls `TelemetryAppender.logException`. Does cleaning, telemetry checks, and data mix-in.
@@ -34,7 +43,7 @@ declare module 'vscode' {
3443
* @param exception The error object which contains the stack trace cleaned of PII
3544
* @param data Additional data to log alongside the stack trace
3645
*/
37-
logError(exception: Error, data?: Record<string, any>): void;
46+
logError(exception: Error, data?: Record<string, any | TrustedTelemetryValue>): void;
3847

3948
dispose(): void;
4049
}

0 commit comments

Comments
 (0)