Skip to content

Commit d5a04dc

Browse files
committed
chore: add observability
1 parent 2cc6114 commit d5a04dc

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"p-limit": "^6.2.0",
104104
"php-array-reader": "^2.1.2",
105105
"plist": "^3.1.0",
106+
"posthog-node": "^4.11.2",
106107
"prettier": "^3.4.2",
107108
"properties-parser": "^0.6.0",
108109
"slugify": "^1.6.6",

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { cacheChunk, deleteCache, getNormalizedCache } from "../utils/cache";
1818
import updateGitignore from "../utils/update-gitignore";
1919
import createProcessor from "../processor";
2020
import { withExponentialBackoff } from "../utils/exp-backoff";
21+
import trackEvent from "../utils/observability";
2122

2223
export default new Command()
2324
.command("i18n")
@@ -61,6 +62,7 @@ export default new Command()
6162
}
6263

6364
let hasErrors = false;
65+
let authId: string | null = null;
6466
try {
6567
ora.start("Loading configuration...");
6668
const i18nConfig = getConfig();
@@ -73,8 +75,14 @@ export default new Command()
7375

7476
ora.start("Connecting to Lingo.dev Localization Engine...");
7577
const auth = await validateAuth(settings);
78+
authId = auth.id;
7679
ora.succeed(`Authenticated as ${auth.email}`);
7780

81+
trackEvent(authId, "cmd.i18n.start", {
82+
i18nConfig,
83+
flags,
84+
});
85+
7886
let buckets = getBuckets(i18nConfig!);
7987
if (flags.bucket?.length) {
8088
buckets = buckets.filter((bucket: any) => flags.bucket!.includes(bucket.type));
@@ -393,11 +401,20 @@ export default new Command()
393401
if (flags.verbose) {
394402
ora.info("Cache file deleted.");
395403
}
404+
trackEvent(auth.id, "cmd.i18n.success", {
405+
i18nConfig,
406+
flags,
407+
});
396408
} else {
397409
ora.warn("Localization completed with errors.");
398410
}
399411
} catch (error: any) {
400412
ora.fail(error.message);
413+
414+
trackEvent(authId || "unknown", "cmd.i18n.error", {
415+
flags,
416+
error,
417+
});
401418
process.exit(1);
402419
}
403420
});

packages/cli/src/cli/utils/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type AuthenticatorParams = {
77

88
export type AuthPayload = {
99
email: string;
10+
id: string;
1011
};
1112

1213
export function createAuthenticator(params: AuthenticatorParams) {
@@ -29,6 +30,7 @@ export function createAuthenticator(params: AuthenticatorParams) {
2930

3031
return {
3132
email: payload.email,
33+
id: payload.id,
3234
};
3335
}
3436

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { PostHog } from "posthog-node";
2+
3+
export default async function trackEvent(distinctId: string, event: string, properties?: Record<string, any>) {
4+
if (process.env.DO_NOT_TRACK) {
5+
return;
6+
}
7+
8+
const posthog = new PostHog("phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk", {
9+
host: "https://eu.i.posthog.com",
10+
});
11+
12+
await posthog.capture({
13+
distinctId,
14+
event,
15+
properties,
16+
});
17+
}

pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)