Registry / devops / vscode-tas-client

vscode-tas-client

JSON →
library0.1.86jsnpmunverified

The `vscode-tas-client` package facilitates A/B experimentation within Visual Studio Code extensions by providing an interface to query and store experiment information from the Microsoft Treatment Assignment Service (TAS). As of version 0.1.86, it is specifically designed for integration with VS Code's extension host environment, leveraging `vscode.Memento` for caching experiment data and `IExperimentationTelemetry` for structured telemetry reporting, including GDPR-classified counterfactual logging. The package manages background refreshes of treatment variables every 30 minutes and offers both synchronous and asynchronous methods for service initialization and variable retrieval, allowing extensions to control data freshness and startup performance. Its core differentiation lies in its tight integration with the VS Code ecosystem, handling aspects like user population targeting, telemetry, and persistence seamlessly for extension developers. The release cadence is typically tied to internal Microsoft development cycles, often aligning with VS Code's own updates.

npm install vscode-tas-client
INSTALL
IMPORT
SIG · VSCODE-TAS-CLIENT
V
vscode-tas-client
devopsjavascriptv0.1.86
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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!'); }
Debug
Known issues
gotchaUsing `getExperimentationService` (synchronous) instead of `getExperimentationServiceAsync` for initial service acquisition might lead to experiment values not being immediately available from cache, potentially serving default values until a background refresh or manual initialization completion. This can result in users not being assigned to the correct experiment group on first run.
fix
Always prefer `getExperimentationServiceAsync` for initial service acquisition. This method awaits the internal `initializePromise`, ensuring cached data is loaded before the service is used for querying treatment variables.
affects: >=0.1.0
gotchaSubsequent calls to `experimentationService.getTreatmentVariable(configId, name)` within the same user session will consistently return the *cached* value obtained during the first call or initialization. This design choice prevents unexpected mid-session user experience changes, even if a background refresh has occurred and new values are available in the cache.
fix
To explicitly force a refresh and retrieve the very latest treatment variable value from the TAS, use `await experimentationService.getTreatmentVariableAsync(configId, name)`. Be mindful that this might cause a network request and could alter the user experience mid-session.
affects: >=0.1.0
gotchaThe `vscode-tas-client` package makes HTTP requests to the TAS server initially upon service acquisition and then periodically every 30 minutes for background refreshes. Extensions operating in environments with strict network policies, offline modes, or limited connectivity should account for this network activity.
fix
Ensure that the VS Code process (and by extension, the extension host) has appropriate network access to reach the TAS endpoints. For testing scenarios that require offline operation, consider mocking the `IExperimentationService`.
affects: >=0.1.0
gotchaThis package is specifically designed for use within the VS Code extension host environment. It relies heavily on VS Code API objects like `vscode.Memento` (via `context.globalState`) and expects an `IExperimentationTelemetry` implementation. Attempting to use it in a standalone Node.js application, browser, or other non-VS Code contexts will lead to runtime errors.
fix
Develop and use this package exclusively within a VS Code extension. For unit testing, mock the `vscode.Memento` and `IExperimentationTelemetry` interfaces to simulate the VS Code environment.
affects: >=0.1.0
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.
fix
Ensure 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.
fix
Always 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.
fix
Verify 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.
Upgrade
Version history
0.1.86latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources