Skip to content

Commit bb14deb

Browse files
authored
chore: upd observability (#1678)
1 parent 785fe74 commit bb14deb

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
Fix inconsistent event tracking in CLI to ensure start/success/error events are always paired correctly for accurate health metrics

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export default new Command()
9393
.action(async function (options) {
9494
updateGitignore();
9595

96+
await trackEvent(null, "cmd.i18n.start", {
97+
rawOptions: options,
98+
});
99+
96100
const ora = Ora();
97101
let flags: ReturnType<typeof parseFlags>;
98102

@@ -109,6 +113,7 @@ export default new Command()
109113
errorCount: 1,
110114
stage: "flag_validation",
111115
});
116+
await new Promise((resolve) => setTimeout(resolve, 50));
112117
throw parseError;
113118
}
114119

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

151-
await trackEvent(authId, "cmd.i18n.start", {
152-
i18nConfig,
153-
flags,
154-
});
155-
156156
let buckets = getBuckets(i18nConfig!);
157157
if (flags.bucket?.length) {
158158
buckets = buckets.filter((bucket: any) =>
@@ -579,6 +579,7 @@ export default new Command()
579579
localeCount: targetLocales.length,
580580
processedSuccessfully: true,
581581
});
582+
await new Promise((resolve) => setTimeout(resolve, 50));
582583
} else {
583584
ora.warn("Localization completed with errors.");
584585
await trackEvent(authId, "cmd.i18n.error", {
@@ -590,6 +591,7 @@ export default new Command()
590591
i18nConfig!,
591592
),
592593
});
594+
await new Promise((resolve) => setTimeout(resolve, 50));
593595
}
594596
} catch (error: any) {
595597
ora.fail(error.message);
@@ -623,6 +625,7 @@ export default new Command()
623625
errorCount: errorDetails.length + 1,
624626
previousErrors: createPreviousErrorContext(errorDetails),
625627
});
628+
await new Promise((resolve) => setTimeout(resolve, 50));
626629
}
627630
});
628631

packages/cli/src/cli/cmd/run/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ export default new Command()
173173
config: ctx.config,
174174
flags: ctx.flags,
175175
});
176+
await new Promise((resolve) => setTimeout(resolve, 50));
176177
} catch (error: any) {
177178
await trackEvent(authId, "cmd.run.error", {});
179+
await new Promise((resolve) => setTimeout(resolve, 50));
178180
// Play sad sound if sound flag is enabled
179181
if (args.sound) {
180182
await playSound("failure");

packages/cli/src/cli/cmd/status.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ export default new Command()
636636
totalWordsToTranslate,
637637
authenticated: !!authId,
638638
});
639+
await new Promise((resolve) => setTimeout(resolve, 50));
639640
exitGracefully();
640641
} catch (error: any) {
641642
ora.fail(error.message);
@@ -644,6 +645,7 @@ export default new Command()
644645
error: error.message,
645646
authenticated: !!authId,
646647
});
648+
await new Promise((resolve) => setTimeout(resolve, 50));
647649
process.exit(1);
648650
}
649651
});

packages/cli/src/cli/utils/observability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getRepositoryId } from "./repository-id";
66
const POSTHOG_API_KEY = "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk";
77
const POSTHOG_HOST = "eu.i.posthog.com";
88
const POSTHOG_PATH = "/i/v0/e/";
9-
const REQUEST_TIMEOUT_MS = 1000;
9+
const REQUEST_TIMEOUT_MS = 3000;
1010
const TRACKING_VERSION = "2.0";
1111

1212
function determineDistinctId(providedId: string | null | undefined): {

0 commit comments

Comments
 (0)