From db7757df323a8221eadd7f94f901ea968d0c5ed7 Mon Sep 17 00:00:00 2001 From: Andrey Avtomonov Date: Fri, 22 May 2026 17:22:25 +0200 Subject: [PATCH] refactor(telemetry): drop no-op groupIdentify, rely on capture groups field --- packages/cli/src/telemetry/emitter.test.ts | 27 ------------- packages/cli/src/telemetry/emitter.ts | 47 ---------------------- 2 files changed, 74 deletions(-) diff --git a/packages/cli/src/telemetry/emitter.test.ts b/packages/cli/src/telemetry/emitter.test.ts index 861c4ab4..9c732997 100644 --- a/packages/cli/src/telemetry/emitter.test.ts +++ b/packages/cli/src/telemetry/emitter.test.ts @@ -2,14 +2,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { __resetTelemetryEmitterForTests, - groupIdentifyProject, shutdownTelemetryEmitter, trackTelemetryEvent, } from './emitter.js'; import type { BuiltTelemetryEvent } from './events.js'; const captures: unknown[] = []; -const groupIdentifies: unknown[] = []; const shutdown = vi.fn(async () => {}); function liveConfigId(): string { @@ -20,7 +18,6 @@ vi.mock('posthog-node', () => ({ PostHog: vi.fn().mockImplementation(function () { return { capture: (event: unknown) => captures.push(event), - groupIdentify: (event: unknown) => groupIdentifies.push(event), shutdown, }; }), @@ -50,7 +47,6 @@ function commandEvent(): BuiltTelemetryEvent<'command'> { describe('telemetry emitter', () => { beforeEach(() => { captures.length = 0; - groupIdentifies.length = 0; shutdown.mockClear(); __resetTelemetryEmitterForTests(); }); @@ -88,29 +84,6 @@ describe('telemetry emitter', () => { }); }); - it('group-identifies once per project when live config is supplied', async () => { - await groupIdentifyProject({ - distinctId: 'install-1', - projectId: 'project-1', - projectApiKey: liveConfigId(), - host: 'https://us.i.posthog.com', - }); - await groupIdentifyProject({ - distinctId: 'install-1', - projectId: 'project-1', - projectApiKey: liveConfigId(), - host: 'https://us.i.posthog.com', - }); - - expect(groupIdentifies).toEqual([ - { - groupType: 'project', - groupKey: 'project-1', - distinctId: 'install-1', - }, - ]); - }); - it('captures with distinctId, properties, and groups when live config is supplied', async () => { await trackTelemetryEvent({ event: commandEvent(), diff --git a/packages/cli/src/telemetry/emitter.ts b/packages/cli/src/telemetry/emitter.ts index 6ce1ebc1..435a122b 100644 --- a/packages/cli/src/telemetry/emitter.ts +++ b/packages/cli/src/telemetry/emitter.ts @@ -16,7 +16,6 @@ type PostHogClient = { properties: Record; groups?: Record; }): void; - groupIdentify(event: { groupType: string; groupKey: string; distinctId?: string }): void; shutdown(): Promise | void; }; @@ -26,7 +25,6 @@ const POSTHOG_HOST = 'https://us.i.posthog.com'; const SHUTDOWN_TIMEOUT_MS = 1500; let clientPromise: Promise | undefined; -const identifiedProjects = new Set(); function telemetryHost(env: TelemetryEmitterEnv, explicitHost?: string): string { return explicitHost ?? env.KTX_TELEMETRY_ENDPOINT ?? POSTHOG_HOST; @@ -72,40 +70,6 @@ function writeDebugPayload(input: { ); } -/** @internal */ -export async function groupIdentifyProject(input: { - distinctId: string; - projectId: string; - env?: TelemetryEmitterEnv; - projectApiKey?: string; - host?: string; -}): Promise { - const env = input.env ?? process.env; - const projectApiKey = telemetryProjectApiKey(input.projectApiKey); - const host = telemetryHost(env, input.host); - const projectKey = `${host}:${input.projectId}`; - - if (identifiedProjects.has(projectKey)) { - return; - } - identifiedProjects.add(projectKey); - - const client = await getPostHogClient(projectApiKey, host); - if (!client) { - return; - } - - try { - client.groupIdentify({ - groupType: 'project', - groupKey: input.projectId, - distinctId: input.distinctId, - }); - } catch { - return; - } -} - export async function trackTelemetryEvent(input: { event: BuiltTelemetryEvent; distinctId: string; @@ -130,16 +94,6 @@ export async function trackTelemetryEvent(input: { } try { - if (input.projectId) { - await groupIdentifyProject({ - distinctId: input.distinctId, - projectId: input.projectId, - env, - projectApiKey, - host, - }); - } - client.capture({ distinctId: input.distinctId, event: input.event.name, @@ -168,5 +122,4 @@ export async function shutdownTelemetryEmitter(): Promise { /** @internal */ export function __resetTelemetryEmitterForTests(): void { clientPromise = undefined; - identifiedProjects.clear(); }