Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
getExperimentationService
✓ import { getExperimentationService } from 'vscode-tas-client';
✗ const getExperimentationService = require('vscode-tas-client').getExperimentationService;
Initializes the experimentation service synchronously. For most cases, `getExperimentationServiceAsync` is preferred to ensure cached data is loaded.
getExperimentationServiceAsync
✓ import { getExperimentationServiceAsync } from 'vscode-tas-client';
✗ const getExperimentationServiceAsync = require('vscode-tas-client').getExperimentationServiceAsync;
Asynchronous initialization; recommended as it awaits the internal `initializePromise` to ensure cached experiment data is loaded before the service instance is returned.
IExperimentationService
✓ import { IExperimentationService } from 'vscode-tas-client';
✗ import IExperimentationService from 'vscode-tas-client';
TypeScript interface representing the experimentation service instance, providing methods like `getTreatmentVariable`.
TargetPopulation
✓ import { TargetPopulation } from 'vscode-tas-client';
✗ const TargetPopulation = require('vscode-tas-client').TargetPopulation;
An enum used to specify the target user ring (e.g., `TargetPopulation.Public`, `TargetPopulation.Insiders`).
IExperimentationTelemetry
✓ import { IExperimentationTelemetry } from 'vscode-tas-client';
✗ type IExperimentationTelemetry = any;
TypeScript interface for the telemetry service, which must be implemented and passed during service initialization to enable experiment analysis and counterfactual logging.
This quickstart initializes the `vscode-tas-client` experimentation service within a VS Code extension's `activate` function and demonstrates how to retrieve treatment variable values, including forcing a refresh for the latest data. It also includes a mock telemetry implementation.
import * as vscode from 'vscode';
import {
getExperimentationServiceAsync,
TargetPopulation,
IExperimentationService,
IExperimentationTelemetry,
} from 'vscode-tas-client';
// A mock implementation for IExperimentationTelemetry to satisfy the interface.
// In a real extension, you would likely use VS Code's built-in telemetry reporter.
class MockTelemetry implements IExperimentationTelemetry {
public commonProperties: Record<string, string> = {};
setCommonProperties(properties: Record<string, string>): void {
this.commonProperties = { ...this.commonProperties, ...properties };
}
postEvent(eventName: string, props?: Record<string, any>): void {
console.log(`Telemetry Event: ${eventName}`, { ...this.commonProperties, ...props });
}
dispose(): void {
// No-op for mock telemetry
}
}
export async function activate(context: vscode.ExtensionContext) {
console.log('Extension "my-experiment-extension" is active!');
const extensionName = 'my-experiment-extension';
const extensionVersion = '1.0.0';
// Determine the target population based on user settings or environment
const targetPopulation = process.env.VSCODE_INSIDERS === 'true' ? TargetPopulation.Insiders : TargetPopulation.Public;
const telemetry = new MockTelemetry();
const memento = context.globalState;
let experimentationService: IExperimentationService;
try {
// Initialize the experimentation service asynchronously to ensure cached data is loaded.
experimentationService = await getExperimentationServiceAsync(
extensionName,
extensionVersion,
targetPopulation,
telemetry,
memento
);
console.log('Experimentation service initialized.');
// Query a treatment variable. 'vscode' is the standard configId.
const myFeatureToggleValue = experimentationService.getTreatmentVariable('vscode', 'myFeatureToggle');
console.log(`Value for 'myFeatureToggle': ${myFeatureToggleValue}`);
// If you need to force a refresh and get the very latest value from TAS,
// use getTreatmentVariableAsync. This will trigger a network request.
const latestMyFeatureToggleValue = await experimentationService.getTreatmentVariableAsync('vscode', 'myFeatureToggle');
console.log(`Latest value for 'myFeatureToggle' after refresh: ${latestMyFeatureToggleValue}`);
} catch (error) {
console.error('Failed to initialize experimentation service:', error);
}
}
// Standard VS Code extension deactivate function.
export function deactivate() {
console.log('Extension "my-experiment-extension" is deactivating!');
}
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'globalState')
The `memento` argument passed to `getExperimentationService` or `getExperimentationServiceAsync` was `undefined` or not a valid `vscode.Memento` instance. This typically occurs when the package is used outside of a VS Code extension's `activate` context or `context.globalState` is not properly provided.
fixEnsure your extension's `activate` function correctly receives `vscode.ExtensionContext` and that `context.globalState` is passed as the `memento` argument to the experimentation service initialization function.
TypeError: experimentationService.getTreatmentVariableAsync is not a function
Attempting to call `getTreatmentVariableAsync` on an `IExperimentationService` instance that was not properly awaited during its acquisition, or attempting to use `getTreatmentVariableAsync` on an outdated version of the service.
fixAlways use `await getExperimentationServiceAsync(...)` to get the service instance. Ensure you are calling `getTreatmentVariableAsync` on the `IExperimentationService` instance, not a raw promise or an uninitialized object. Verify your package version supports the async method.
Telemetry Event: query-expfeature {...} (but no expected experiment data)
The telemetry event `query-expfeature` is sent, but the associated common properties (`vscode.abexp.features` or `abexp.assignmentcontext`) or the expected treatment variable values are missing or are default values, indicating the experiment data was not successfully loaded.
fixVerify that `getExperimentationServiceAsync` was used for initialization. Check network connectivity to TAS and ensure your `extensionName`, `extensionVersion`, and `targetPopulation` are correctly configured, as these are used for traffic filtering.
Audit
Dependencies
No dependency data recorded yet.