Skip to content

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

fix(cli): configure telemetry before invocation

Kshitij Jhunjhunwala87236ff642cd
diff --git a/ts/packages/cli/src/analytics/events.ts b/ts/packages/cli/src/analytics/events.ts
index c483c8556..55b61e43d 100644
--- a/ts/packages/cli/src/analytics/events.ts
+++ b/ts/packages/cli/src/analytics/events.ts
@@ -114,14 +114,18 @@ export const configureCliAnalyticsReleaseVersion = (version: string): void => {
const buildEvent = (
name: CliAnalyticsEventName,
properties: Record<string, unknown>
-): TrackEvent => ({
- name,
- properties: {
- ...properties,
- journey_stage: CLI_EVENT_JOURNEY_STAGES[name],
- cli_channel: cliChannel,
- },
-});
+): TrackEvent => {
+ const eventVersion =
+ typeof properties.cli_version === 'string' ? properties.cli_version : undefined;
+ return {
+ name,
+ properties: {
+ ...properties,
+ journey_stage: CLI_EVENT_JOURNEY_STAGES[name],
+ cli_channel: eventVersion ? inferSkillReleaseChannel(eventVersion) : cliChannel,
+ },
+ };
+};
const KNOWN_COMMAND_TOKENS = new Set([
'version',
diff --git a/ts/packages/cli/src/cli-main.ts b/ts/packages/cli/src/cli-main.ts
index d26092b43..93fcb1c22 100644
--- a/ts/packages/cli/src/cli-main.ts
+++ b/ts/packages/cli/src/cli-main.ts
@@ -36,12 +36,14 @@ import { CommandRunner } from 'src/services/command-runner';
import { StdinLive } from 'src/services/stdin';
import { showUpdateNotice } from 'src/services/update-check';
import {
+ configureCliAnalyticsReleaseVersion,
createCliCommandTelemetryContext,
getPrimaryLifecycleFailedEvent,
getPrimaryLifecycleInvokedEvent,
getPrimaryLifecycleSucceededEvent,
} from 'src/analytics/events';
import { ensureAnalyticsIdentity, trackCliEventEffect } from 'src/analytics/dispatch';
+import { getVersion } from 'src/effects/version';
import { mapOnlyComposioOverrideError } from 'src/services/composio-error-overrides';
import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
import { SetupCommandError } from 'src/services/setup';
@@ -161,11 +163,9 @@ const runWithTelemetry = Effect.gen(function* () {
});
}
- const commandTelemetryContext = createCliCommandTelemetryContext(
- process.argv,
- constants.APP_VERSION,
- terminal
- );
+ const version = yield* getVersion;
+ configureCliAnalyticsReleaseVersion(version);
+ const commandTelemetryContext = createCliCommandTelemetryContext(process.argv, version, terminal);
if (commandTelemetryContext.commandPath === 'run' && commandTelemetryContext.runId) {
// effect/Config is read-only; the run id must be written into the environment so the run
// command and the child processes it spawns observe the same telemetry run id.
diff --git a/ts/packages/cli/test/src/analytics.events.test.ts b/ts/packages/cli/test/src/analytics.events.test.ts
index ae5456d8f..b08be9213 100644
--- a/ts/packages/cli/test/src/analytics.events.test.ts
+++ b/ts/packages/cli/test/src/analytics.events.test.ts
@@ -454,12 +454,30 @@ describe('CLI analytics journey taxonomy', () => {
const resolvedVersion = yield* resolveInstalledCliVersion(execPath, APP_VERSION);
configureCliAnalyticsReleaseVersion(resolvedVersion);
- const properties = getPrimaryLifecycleInvokedEvent(contextFor(['login']))?.properties;
+ const context = createCliCommandTelemetryContext(
+ ['bun', 'composio', 'login'],
+ resolvedVersion,
+ { stdoutIsTTY: false, stderrIsTTY: false }
+ );
+ const properties = getPrimaryLifecycleInvokedEvent(context)?.properties;
expect(inferSkillReleaseChannel(APP_VERSION)).toBe('stable');
expect(properties?.cli_channel).toBe('beta');
}).pipe(Effect.provide(Layer.merge(BunFileSystem.layer, BunPath.layer)));
});
+ it('derives invoked-event channel from its resolved runtime version', () => {
+ configureCliAnalyticsReleaseVersion(APP_VERSION);
+ const context = createCliCommandTelemetryContext(['bun', 'composio', 'login'], '0.3.1-beta.7', {
+ stdoutIsTTY: true,
+ stderrIsTTY: true,
+ });
+
+ expect(getPrimaryLifecycleInvokedEvent(context)?.properties).toMatchObject({
+ cli_version: '0.3.1-beta.7',
+ cli_channel: 'beta',
+ });
+ });
+
it('propagates the installer invocation origin from the environment', () => {
vi.stubEnv('COMPOSIO_CLI_INVOCATION_ORIGIN', 'installer');