Skip to content

Commit fde18b2

Browse files
committed
Adds device cohort to tracking
1 parent 0ab9eaa commit fde18b2

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

docs/telemetry-events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'global.cloudIntegrations.connected.count': number,
2929
'global.cloudIntegrations.connected.ids': string,
3030
'global.debugging': boolean,
31+
'global.device.cohort': number,
3132
'global.enabled': boolean,
3233
'global.folders.count': number,
3334
'global.folders.schemes': string,

src/constants.telemetry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface TelemetryGlobalContext extends SubscriptionEventData {
2626
'cloudIntegrations.connected.count': number;
2727
'cloudIntegrations.connected.ids': string;
2828
debugging: boolean;
29+
/** Cohort number between 1 and 100 to use for percentage-based rollouts */
30+
'device.cohort': number;
2931
enabled: boolean;
3032
prerelease: boolean;
3133
install: boolean;

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { executeCommand, registerCommands } from './system/-webview/command';
2525
import { configuration, Configuration } from './system/-webview/configuration';
2626
import { setContext } from './system/-webview/context';
2727
import { Storage } from './system/-webview/storage';
28-
import { isTextDocument, isTextEditor, isWorkspaceFolder } from './system/-webview/vscode';
28+
import { deviceCohortGroup, isTextDocument, isTextEditor, isWorkspaceFolder } from './system/-webview/vscode';
2929
import { setDefaultDateLocales } from './system/date';
3030
import { once } from './system/event';
3131
import { BufferedLogChannel, getLoggableName, Logger } from './system/logger';
@@ -237,6 +237,7 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |
237237

238238
container.telemetry.setGlobalAttributes({
239239
debugging: container.debugging,
240+
'device.cohort': deviceCohortGroup,
240241
prerelease: prerelease,
241242
install: previousVersion == null,
242243
upgrade: previousVersion != null && gitlensVersion !== previousVersion,

src/plus/gk/productConfigProvider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { env } from 'vscode';
21
import { SubscriptionState } from '../../constants.subscription';
32
import type { Container } from '../../container';
3+
import { deviceCohortGroup } from '../../system/-webview/vscode';
44
import type { Lazy } from '../../system/lazy';
55
import { lazy } from '../../system/lazy';
66
import { getLoggableName, Logger } from '../../system/logger';
77
import { startLogScope } from '../../system/logger.scope';
8-
import { getPercentileGroup } from '../../system/string';
98
import type { Validator } from '../../system/validation';
109
import { createValidator, Is } from '../../system/validation';
1110
import type { Promo, PromoLocation } from './models/promo';
@@ -211,6 +210,6 @@ function isPromoApplicable(promo: Promo, state: number): boolean {
211210
(promo.states == null || promo.states.includes(state)) &&
212211
(promo.expiresOn == null || promo.expiresOn > now) &&
213212
(promo.startsOn == null || promo.startsOn < now) &&
214-
(promo.percentile == null || getPercentileGroup(env.machineId) <= promo.percentile)
213+
(promo.percentile == null || deviceCohortGroup <= promo.percentile)
215214
);
216215
}

src/system/-webview/vscode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import type { Container } from '../../container';
1515
import { isGitUri } from '../../git/gitUri';
1616
import { Logger } from '../logger';
1717
import { extname, joinPaths, normalizePath } from '../path';
18+
import { getDistributionGroup } from '../string';
1819
import { satisfies } from '../version';
1920
import { executeCoreCommand } from './command';
2021
import { configuration } from './configuration';
2122
import { relative } from './path';
2223

24+
export const deviceCohortGroup = getDistributionGroup(env.machineId);
25+
2326
export function findTextDocument(uri: Uri): TextDocument | undefined {
2427
const normalizedUri = uri.toString();
2528
return workspace.textDocuments.find(d => d.uri.toString() === normalizedUri);

src/system/string.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ export function* getLines(data: string | string[], char: string = '\n'): Iterabl
184184
}
185185

186186
/**
187-
* Groups a value into a percentile group (1-100)
188-
* @param value The value group by (e.g., machine ID)
189-
* @returns A number between 1-100 representing the percentile group
187+
* Distributes a value into one of 100 groups based on a hash of the value
188+
* @param value The value to distribute (e.g., machine ID)
189+
* @returns A number between 1-100 representing the distribution group
190190
*/
191-
export function getPercentileGroup(value: string): number {
191+
export function getDistributionGroup(value: string): number {
192192
// Simple hash function
193193
let hash = 0;
194194
for (let i = 0; i < value.length; i++) {
@@ -197,8 +197,8 @@ export function getPercentileGroup(value: string): number {
197197
}
198198

199199
// Convert hash to a number between 1-100
200-
const percentile = Math.abs(hash % 100) + 1;
201-
return percentile;
200+
const group = Math.abs(hash % 100) + 1;
201+
return group;
202202
}
203203

204204
export function getPossessiveForm(name: string): string {

0 commit comments

Comments
 (0)