@devries-cameron20 / composio-1 / commits / 28717a963
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(cli): attach org_id to telemetry events

Going direct to PostHog dropped the org/project context Apollo's Segment path enriched server-side. org_id is available in ~/.composio/user_data.json — which the analytics worker already reads — so post-login events now carry it. project_id is per-session and not reliably in user config, so it is left for a follow-up rather than fabricated; the PR description is corrected accordingly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Jul 24, 2026 at 09:35 UTC 28717a96317b7bc823ad0e7761f77164af4e36a2
2 files changed +38 -2
ts/packages/cli/src/analytics/dispatch.ts
+13 -2
@@ -234,9 +234,15 @@ const mergeAnalyticsState = (installId: string, patch: Partial<AnalyticsState>)
234
235 const readUserConfig = Effect.gen(function* () {
236 const paths = yield* getAnalyticsPaths;
237 - return yield* readOptionalJson<{ api_key?: unknown; base_url?: unknown }>(paths.userConfigPath);
237 + return yield* readOptionalJson<{ api_key?: unknown; base_url?: unknown; org_id?: unknown }>(
238 + paths.userConfigPath
239 + );
240 });
241
242 +const getOrgId = Effect.map(readUserConfig, config =>
243 + typeof config?.org_id === 'string' && config.org_id.length > 0 ? config.org_id : null
244 +);
245 +
246 const getUserApiKey = Effect.gen(function* () {
247 const envApiKey = configuredString(
248 yield* environmentProvider.load(optionalString('COMPOSIO_USER_API_KEY'))
@@ -554,10 +560,15 @@ export const trackCliEventEffect = (event: TrackEvent) =>
560
561 const installId = yield* getOrCreateInstallId;
562 const distinctId = yield* getDistinctId(installId);
563 + const orgId = yield* getOrgId;
564 const sentAt = DateTime.formatIso(yield* DateTime.now);
565 + const properties = {
566 + ...(enrichedEvent.properties ?? {}),
567 + ...(orgId ? { org_id: orgId } : {}),
568 + };
569 const envelope: AnalyticsEnvelope = {
570 event: enrichedEvent.name,
560 - ...(enrichedEvent.properties ? { properties: enrichedEvent.properties } : {}),
571 + ...(Object.keys(properties).length > 0 ? { properties } : {}),
572 sentAt,
573 source: 'cli',
574 distinctId,
ts/packages/cli/test/src/analytics.dispatch.test.ts
+25
@@ -734,6 +734,31 @@ describe('CLI analytics dispatch', () => {
734 }).pipe(Effect.provide(makePlatformLayer(home)));
735 });
736
737 + it.effect('attaches org_id from user config to events', () => {
738 + const home = tempy.temporaryDirectory();
739 + const scriptPath = `${home}/composio.ts`;
740 + enableTelemetry();
741 + process.argv[1] = scriptPath;
742 +
743 + return Effect.gen(function* () {
744 + const fs = yield* FileSystem.FileSystem;
745 + const path = yield* Path.Path;
746 + yield* fs.writeFileString(scriptPath, '');
747 + const composioDir = path.join(home, '.composio');
748 + yield* fs.makeDirectory(composioDir, { recursive: true });
749 + yield* fs.writeFileString(
750 + path.join(composioDir, USER_CONFIG_FILE_NAME),
751 + JSON.stringify({ api_key: 'uak_test', org_id: 'org_acme' })
752 + );
753 +
754 + yield* trackCliEventEffect({ name: 'producer_event' });
755 +
756 + const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];
757 + const payload = decodeWorkerPayload<{ properties?: { org_id?: string } }>(args[2]!);
758 + expect(payload.properties?.org_id).toBe('org_acme');
759 + }).pipe(Effect.provide(makePlatformLayer(home)));
760 + });
761 +
762 it.effect('does not create the identity file when logging out with telemetry disabled', () => {
763 const home = tempy.temporaryDirectory();
764 enableTelemetry();