Skip to content
Open
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
8 changes: 8 additions & 0 deletions extensions/copilot/src/lib/node/chatLibMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export interface ILogTarget {
export interface ITelemetrySender {
sendTelemetryEvent(eventName: string, properties?: Record<string, string | undefined>, measurements?: Record<string, number | undefined>): void;
sendEnhancedTelemetryEvent?(eventName: string, properties?: Record<string, string | undefined>, measurements?: Record<string, number | undefined>): void;
setExperimentProperty?(name: string, value: string): void;
}

export interface INESProviderOptions {
Expand Down Expand Up @@ -679,6 +680,9 @@ class SimpleTelemetryService implements ITelemetryService {
return;
}
setSharedProperty(name: string, value: string): void {
if (name === 'capi.assignmentcontext') {
this._telemetrySender.setExperimentProperty?.(name, value);
}
return;
}
setAdditionalExpAssignments(expAssignments: string[]): void {
Expand Down Expand Up @@ -879,6 +883,10 @@ class UnwrappingTelemetrySender implements ITelemetrySender {
}
}

setExperimentProperty(name: string, value: string): void {
this.sender.setExperimentProperty?.(name, value);
}

private normalizeEventName(eventName: string): string {
const unwrapped = unwrapEventNameFromPrefix(eventName);
const withoutPrefix = unwrapped.match(/^[^/]+\/(.*)/);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { CustomFetcher } from '@vscode/extension-telemetry';
import * as vscode from 'vscode';
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
import { ICopilotTokenStore } from '../../authentication/common/copilotTokenStore';
import { ConfigKey, IConfigurationService } from '../../configuration/common/configurationService';
Expand Down Expand Up @@ -120,4 +121,15 @@ export class TelemetryService extends BaseTelemetryService {
});
}
}

// __GDPR__COMMON__ "capi.assignmentcontext" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
override setSharedProperty(name: string, value: string): void {
super.setSharedProperty(name, value);

// Forward CAPI assignment context to the core telemetry pipeline
// so it appears on all telemetry events from the current window.
if (name === 'capi.assignmentcontext') {
vscode.commands.executeCommand('_telemetry.setCapiAssignmentContext', value);
}
}
}
20 changes: 20 additions & 0 deletions src/vs/workbench/api/browser/mainThreadTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { Disposable } from '../../../base/common/lifecycle.js';
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
import { CommandsRegistry } from '../../../platform/commands/common/commands.js';
import { IEnvironmentService } from '../../../platform/environment/common/environment.js';
import { IProductService } from '../../../platform/product/common/productService.js';
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from '../../../platform/telemetry/common/gdprTypings.js';
Expand Down Expand Up @@ -59,4 +60,23 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
}
}

const capiAssignmentContextPropertyName = 'capi.assignmentcontext';
const maxCapiAssignmentContextLength = 8 * 1024;
const capiAssignmentContextEntryPattern = /^[^:;\s\x00-\x1F\x7F]+:[^;\x00-\x1F\x7F]+$/;

function isValidCapiAssignmentContext(value: string): boolean {
if (value.length === 0 || value.length > maxCapiAssignmentContextLength) {
return false;
}

const entries = value.split(';');
return entries.length > 0 && entries.every(entry => capiAssignmentContextEntryPattern.test(entry));
}

CommandsRegistry.registerCommand('_telemetry.setCapiAssignmentContext', function (accessor, value: string) {
if (!isValidCapiAssignmentContext(value)) {
return;
}

accessor.get(ITelemetryService).setExperimentProperty(capiAssignmentContextPropertyName, value);
});
Loading