Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { ICopilotTokenStore } from '../../authentication/common/copilotTokenStor
import { ICAPIClientService } from '../../endpoint/common/capiClient';
import { BaseGHTelemetrySender } from './ghTelemetrySender';
import { BaseMsftTelemetrySender } from './msftTelemetrySender';
import { ITelemetryService, TelemetryDestination, TelemetryEventMeasurements, TelemetryEventProperties } from './telemetry';
import { ITelemetryService, TelemetryDestination, TelemetryEventMeasurements, TelemetryEventProperties, TelemetryTrustedValue } from './telemetry';

export class BaseTelemetryService implements ITelemetryService {
declare readonly _serviceBrand: undefined;
// Properties that are applied to all telemetry events (currently only used by the exp service
// TODO @lramos15 extend further to include more
private _sharedProperties: Record<string, string> = {};
private _sharedProperties: Record<string, string | TelemetryTrustedValue<string>> = {};
private _originalExpAssignments: string | undefined;
private _additionalExpAssignments: string[] = [];
private _disposables: IDisposable[] = [];
Expand Down Expand Up @@ -143,7 +143,7 @@ export class BaseTelemetryService implements ITelemetryService {
}
}
this._capiClientService.abExpContext = value;
this._sharedProperties['abexp.assignmentcontext'] = value;
this._sharedProperties['abexp.assignmentcontext'] = new TelemetryTrustedValue(value);
}

setSharedProperty(name: string, value: string): void {
Expand All @@ -165,9 +165,11 @@ export class BaseTelemetryService implements ITelemetryService {
}

postEvent(eventName: string, props: Map<string, string>): void {
for (const [key, value] of Object.entries(this._sharedProperties)) {
props.set(key, value);
}
this._microsoftTelemetrySender.postEvent(eventName, props);
const properties: Record<string, string | TelemetryTrustedValue<string>> = {
...Object.fromEntries(props),
...this._sharedProperties
};
this._microsoftTelemetrySender.sendInternalTelemetryEvent(eventName, properties);
this._microsoftTelemetrySender.sendTelemetryEvent(eventName, properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,6 @@ export class BaseMsftTelemetrySender implements IMSFTTelemetrySender {
this._disposables.add(copilotTokenStore.onDidStoreUpdate(() => this.processToken(copilotTokenStore.copilotToken)));
}

/**
* **NOTE**: Do not call directly
* This is just used by the experimentation service to log events to the scorecards
* @param eventName
* @param props
*/
postEvent(eventName: string, props: Map<string, string>): void {
const event: Record<string, string> = {};
for (const [key, value] of props) {
event[key] = value;
}
if (this._isInternal) {
this.sendInternalTelemetryEvent(eventName, event);
}
this.sendTelemetryEvent(eventName, event);
}

/**
* Sends a telemetry event regarding internal Microsoft staff only. Will be dropped if telemetry level is below Usage
* @param eventName The name of the event to send
Expand All @@ -61,7 +44,7 @@ export class BaseMsftTelemetrySender implements IMSFTTelemetrySender {
* @returns
*/
sendInternalTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void {
if (!this._internalTelemetryReporter) {
if (!this._internalTelemetryReporter || !this._isInternal) {
return;
}
properties = { ...properties, 'common.tid': this._tid, 'common.userName': this._username ?? 'undefined' };
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/telemetry/common/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IProductService } from '../../product/common/productService.js';
import { Registry } from '../../registry/common/platform.js';
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from './gdprTypings.js';
import { ITelemetryData, ITelemetryService, TelemetryConfiguration, TelemetryLevel, TELEMETRY_CRASH_REPORTER_SETTING_ID, TELEMETRY_OLD_SETTING_ID, TELEMETRY_SECTION_ID, TELEMETRY_SETTING_ID, ICommonProperties } from './telemetry.js';
import { cleanData, getTelemetryLevel, ITelemetryAppender } from './telemetryUtils.js';
import { cleanData, getTelemetryLevel, ITelemetryAppender, TelemetryTrustedValue } from './telemetryUtils.js';

export interface ITelemetryServiceConfig {
appenders: ITelemetryAppender[];
Expand Down Expand Up @@ -60,7 +60,7 @@ export class TelemetryService implements ITelemetryService {

private _appenders: ITelemetryAppender[];
private _commonProperties: ICommonProperties;
private _experimentProperties: { [name: string]: string } = {};
private _experimentProperties: { [name: string]: string | TelemetryTrustedValue<string> } = {};
private _piiPaths: string[];
private _telemetryLevel: TelemetryLevel;
private _sendErrorTelemetry: boolean;
Expand Down Expand Up @@ -127,7 +127,7 @@ export class TelemetryService implements ITelemetryService {
}

setExperimentProperty(name: string, value: string): void {
this._experimentProperties[name] = value;
this._experimentProperties[name] = new TelemetryTrustedValue(value);

// On first call, flush all pending events that were buffered waiting for experiment properties
if (!this._isExperimentPropertySet) {
Expand Down
Loading