Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
feat(cli): attach org_id to telemetry events
Kshitij Jhunjhunwala28717a96317b
diff --git a/ts/packages/cli/src/analytics/dispatch.ts b/ts/packages/cli/src/analytics/dispatch.tsindex d31cfc8ef..5ce99bef4 100644--- a/ts/packages/cli/src/analytics/dispatch.ts+++ b/ts/packages/cli/src/analytics/dispatch.ts@@ -234,9 +234,15 @@ const mergeAnalyticsState = (installId: string, patch: Partial<AnalyticsState>)const readUserConfig = Effect.gen(function* () {const paths = yield* getAnalyticsPaths;- return yield* readOptionalJson<{ api_key?: unknown; base_url?: unknown }>(paths.userConfigPath);+ return yield* readOptionalJson<{ api_key?: unknown; base_url?: unknown; org_id?: unknown }>(+ paths.userConfigPath+ );});+const getOrgId = Effect.map(readUserConfig, config =>+ typeof config?.org_id === 'string' && config.org_id.length > 0 ? config.org_id : null+);+const getUserApiKey = Effect.gen(function* () {const envApiKey = configuredString(yield* environmentProvider.load(optionalString('COMPOSIO_USER_API_KEY'))@@ -554,10 +560,15 @@ export const trackCliEventEffect = (event: TrackEvent) =>const installId = yield* getOrCreateInstallId;const distinctId = yield* getDistinctId(installId);+ const orgId = yield* getOrgId;const sentAt = DateTime.formatIso(yield* DateTime.now);+ const properties = {+ ...(enrichedEvent.properties ?? {}),+ ...(orgId ? { org_id: orgId } : {}),+ };const envelope: AnalyticsEnvelope = {event: enrichedEvent.name,- ...(enrichedEvent.properties ? { properties: enrichedEvent.properties } : {}),+ ...(Object.keys(properties).length > 0 ? { properties } : {}),sentAt,source: 'cli',distinctId,diff --git a/ts/packages/cli/test/src/analytics.dispatch.test.ts b/ts/packages/cli/test/src/analytics.dispatch.test.tsindex e5d9d1004..2a4073e28 100644--- a/ts/packages/cli/test/src/analytics.dispatch.test.ts+++ b/ts/packages/cli/test/src/analytics.dispatch.test.ts@@ -734,6 +734,31 @@ describe('CLI analytics dispatch', () => {}).pipe(Effect.provide(makePlatformLayer(home)));});+ it.effect('attaches org_id from user config to events', () => {+ const home = tempy.temporaryDirectory();+ const scriptPath = `${home}/composio.ts`;+ enableTelemetry();+ process.argv[1] = scriptPath;++ return Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ yield* fs.writeFileString(scriptPath, '');+ const composioDir = path.join(home, '.composio');+ yield* fs.makeDirectory(composioDir, { recursive: true });+ yield* fs.writeFileString(+ path.join(composioDir, USER_CONFIG_FILE_NAME),+ JSON.stringify({ api_key: 'uak_test', org_id: 'org_acme' })+ );++ yield* trackCliEventEffect({ name: 'producer_event' });++ const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];+ const payload = decodeWorkerPayload<{ properties?: { org_id?: string } }>(args[2]!);+ expect(payload.properties?.org_id).toBe('org_acme');+ }).pipe(Effect.provide(makePlatformLayer(home)));+ });+it.effect('does not create the identity file when logging out with telemetry disabled', () => {const home = tempy.temporaryDirectory();enableTelemetry();