Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-tracking-event-pairs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"lingo.dev": patch
---

Fix inconsistent event tracking in CLI to ensure start/success/error events are always paired correctly for accurate health metrics
13 changes: 8 additions & 5 deletions packages/cli/src/cli/cmd/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export default new Command()
.action(async function (options) {
updateGitignore();

await trackEvent(null, "cmd.i18n.start", {
rawOptions: options,
});

const ora = Ora();
let flags: ReturnType<typeof parseFlags>;

Expand All @@ -109,6 +113,7 @@ export default new Command()
errorCount: 1,
stage: "flag_validation",
});
await new Promise((resolve) => setTimeout(resolve, 50));
throw parseError;
}

Expand Down Expand Up @@ -148,11 +153,6 @@ export default new Command()
ora.succeed(`Authenticated as ${auth.email}`);
}

await trackEvent(authId, "cmd.i18n.start", {
i18nConfig,
flags,
});

let buckets = getBuckets(i18nConfig!);
if (flags.bucket?.length) {
buckets = buckets.filter((bucket: any) =>
Expand Down Expand Up @@ -579,6 +579,7 @@ export default new Command()
localeCount: targetLocales.length,
processedSuccessfully: true,
});
await new Promise((resolve) => setTimeout(resolve, 50));
} else {
ora.warn("Localization completed with errors.");
await trackEvent(authId, "cmd.i18n.error", {
Expand All @@ -590,6 +591,7 @@ export default new Command()
i18nConfig!,
),
});
await new Promise((resolve) => setTimeout(resolve, 50));
}
} catch (error: any) {
ora.fail(error.message);
Expand Down Expand Up @@ -623,6 +625,7 @@ export default new Command()
errorCount: errorDetails.length + 1,
previousErrors: createPreviousErrorContext(errorDetails),
});
await new Promise((resolve) => setTimeout(resolve, 50));
}
});

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cli/cmd/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ export default new Command()
config: ctx.config,
flags: ctx.flags,
});
await new Promise((resolve) => setTimeout(resolve, 50));
} catch (error: any) {
await trackEvent(authId, "cmd.run.error", {});
await new Promise((resolve) => setTimeout(resolve, 50));
// Play sad sound if sound flag is enabled
if (args.sound) {
await playSound("failure");
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cli/cmd/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ export default new Command()
totalWordsToTranslate,
authenticated: !!authId,
});
await new Promise((resolve) => setTimeout(resolve, 50));
exitGracefully();
} catch (error: any) {
ora.fail(error.message);
Expand All @@ -644,6 +645,7 @@ export default new Command()
error: error.message,
authenticated: !!authId,
});
await new Promise((resolve) => setTimeout(resolve, 50));
process.exit(1);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli/utils/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRepositoryId } from "./repository-id";
const POSTHOG_API_KEY = "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk";
const POSTHOG_HOST = "eu.i.posthog.com";
const POSTHOG_PATH = "/i/v0/e/";
const REQUEST_TIMEOUT_MS = 1000;
const REQUEST_TIMEOUT_MS = 3000;
const TRACKING_VERSION = "2.0";

function determineDistinctId(providedId: string | null | undefined): {
Expand Down