Skip to content

Commit 5ca8439

Browse files
authored
chore: simplify observability (#1874)
* chore: simplify observability * chore: add changeset
1 parent 12b2c08 commit 5ca8439

File tree

15 files changed

+384
-397
lines changed

15 files changed

+384
-397
lines changed

‎.changeset/nine-apes-spend.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@lingo.dev/compiler": patch
3+
"@lingo.dev/_compiler": patch
4+
"lingo.dev": patch
5+
---
6+
7+
simplify observability

‎demo/new-compiler-vite-react-spa/public/translations/de.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"version": 0.1,
33
"locale": "de",
44
"entries": {
5-
"daa4d8839395": "{counter} mal geklickt",
6-
"52ed9ee761d8": "Hallo Welt",
7-
"f11fc78c3ac0": "<b0>Gemischter</b0> Inhalt <i0>Fragment</i0>",
8-
"556f5956dca7": "Willkommen zur Lingo.dev Compiler Demo",
9-
"02704ec4e52a": "Es extrahiert automatisch Text aus Ihrem JSX und übersetzt ihn in andere Sprachen.",
10-
"de6bfb30be49": "Text, der als <code0></code0> eingefügt wird, wird nicht übersetzt: {text}",
11-
"5c15bd35e916": "Um es zu übersetzen, müssen Sie es in '<'>{translatableText} '<'/> einschließen",
12-
"93b50fe805b7": "Text außerhalb der Komponente wird nicht übersetzt: {externalText}",
13-
"d756b03ffbf5": "Inhalte, die Text und andere Tags enthalten, werden als eine Einheit übersetzt: {translatableMixedContextFragment}",
145
"8492c53cfbaf": "Über Lingo.dev",
156
"8aa4fe3f0590": "Dies ist eine Demo-Anwendung, die den Lingo.dev-Compiler für automatische Übersetzungen in React-Anwendungen präsentiert.",
167
"af76f667703b": "Hauptfunktionen",
@@ -21,6 +12,15 @@
2112
"aca12d550fe2": "Unterstützung für Server- und Client-Komponenten",
2213
"44a3311c3a4a": "Wie es funktioniert",
2314
"0add30e37450": "Der Compiler analysiert Ihre React-Komponenten zur Build-Zeit und extrahiert automatisch alle übersetzbaren Strings. Anschließend generiert er Übersetzungen mit Ihrem konfigurierten Übersetzungsanbieter.",
24-
"07d84d34dd3a": "Fügen Sie einfach die Direktive \"use i18n\" am Anfang Ihrer Komponentendateien hinzu, und der Compiler erledigt den Rest!"
15+
"07d84d34dd3a": "Fügen Sie einfach die Direktive \"use i18n\" am Anfang Ihrer Komponentendateien hinzu, und der Compiler erledigt den Rest!",
16+
"daa4d8839395": "{counter} mal geklickt",
17+
"52ed9ee761d8": "Hallo Welt",
18+
"f11fc78c3ac0": "<b0>Gemischter</b0> Inhalt <i0>Fragment</i0>",
19+
"556f5956dca7": "Willkommen zur Lingo.dev Compiler Demo",
20+
"02704ec4e52a": "Es extrahiert automatisch Text aus Ihrem JSX und übersetzt ihn in andere Sprachen.",
21+
"de6bfb30be49": "Text, der als <code0></code0> eingefügt wird, wird nicht übersetzt: {text}",
22+
"5c15bd35e916": "Um es zu übersetzen, müssen Sie es in '<'>{translatableText} '<'/> einschließen",
23+
"93b50fe805b7": "Text außerhalb der Komponente wird nicht übersetzt: {externalText}",
24+
"d756b03ffbf5": "Inhalte, die Text und andere Tags enthalten, werden als eine Einheit übersetzt: {translatableMixedContextFragment}"
2525
}
2626
}

‎demo/new-compiler-vite-react-spa/public/translations/en.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"version": 0.1,
33
"locale": "en",
44
"entries": {
5-
"daa4d8839395": "Clicked {counter} times",
6-
"52ed9ee761d8": "Hello World",
7-
"f11fc78c3ac0": "<b0>Mixed</b0> content <i0>fragment</i0>",
8-
"556f5956dca7": "Welcome to Lingo.dev compiler demo",
9-
"02704ec4e52a": "It automatically extract text from your JSX and translate it to other languages.",
10-
"de6bfb30be49": "Text inserted as an <code0></code0> is not translated: {text}",
11-
"5c15bd35e916": "To translate it you have to wrap it into the '<'>{translatableText} '<'/>",
12-
"93b50fe805b7": "Text external to the component is not translated: {externalText}",
13-
"d756b03ffbf5": "Content that has text and other tags inside will br translated as a single entity: {translatableMixedContextFragment}",
145
"8492c53cfbaf": "About Lingo.dev",
156
"8aa4fe3f0590": "This is a demo application showcasing the Lingo.dev compiler for automatic translations in React applications.",
167
"af76f667703b": "Key Features",
@@ -21,6 +12,15 @@
2112
"aca12d550fe2": "Server and client component support",
2213
"44a3311c3a4a": "How It Works",
2314
"0add30e37450": "The compiler analyzes your React components at build time and automatically extracts all translatable strings. It then generates translations using your configured translation provider.",
24-
"07d84d34dd3a": "Simply add the \"use i18n\" directive at the top of your component files, and the compiler handles the rest!"
15+
"07d84d34dd3a": "Simply add the \"use i18n\" directive at the top of your component files, and the compiler handles the rest!",
16+
"daa4d8839395": "Clicked {counter} times",
17+
"52ed9ee761d8": "Hello World",
18+
"f11fc78c3ac0": "<b0>Mixed</b0> content <i0>fragment</i0>",
19+
"556f5956dca7": "Welcome to Lingo.dev compiler demo",
20+
"02704ec4e52a": "It automatically extract text from your JSX and translate it to other languages.",
21+
"de6bfb30be49": "Text inserted as an <code0></code0> is not translated: {text}",
22+
"5c15bd35e916": "To translate it you have to wrap it into the '<'>{translatableText} '<'/>",
23+
"93b50fe805b7": "Text external to the component is not translated: {externalText}",
24+
"d756b03ffbf5": "Content that has text and other tags inside will br translated as a single entity: {translatableMixedContextFragment}"
2525
}
2626
}

‎demo/new-compiler-vite-react-spa/public/translations/es.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"version": 0.1,
33
"locale": "es",
44
"entries": {
5-
"daa4d8839395": "Clicado {counter} veces",
6-
"52ed9ee761d8": "Hola Mundo",
7-
"f11fc78c3ac0": "Contenido <b0>mixto</b0> <i0>fragmento</i0>",
8-
"556f5956dca7": "Bienvenido a la demo de Lingo.dev compiler",
9-
"02704ec4e52a": "Extrae automáticamente texto de tu JSX y lo traduce a otros idiomas.",
10-
"de6bfb30be49": "El texto insertado como <code0></code0> no se traduce: {text}",
11-
"5c15bd35e916": "Para traducirlo tienes que envolverlo en el '<'>{translatableText} '<'/>",
12-
"93b50fe805b7": "El texto externo al componente no se traduce: {externalText}",
13-
"d756b03ffbf5": "El contenido que tiene texto y otras etiquetas dentro se traducirá como una sola entidad: {translatableMixedContextFragment}",
145
"8492c53cfbaf": "Acerca de Lingo.dev",
156
"8aa4fe3f0590": "Esta es una aplicación de demostración que muestra el compilador Lingo.dev para traducciones automáticas en aplicaciones React.",
167
"af76f667703b": "Características principales",
@@ -21,6 +12,15 @@
2112
"aca12d550fe2": "Soporte para componentes de servidor y cliente",
2213
"44a3311c3a4a": "Cómo funciona",
2314
"0add30e37450": "El compilador analiza tus componentes de React en tiempo de compilación y extrae automáticamente todas las cadenas traducibles. Luego genera traducciones utilizando tu proveedor de traducción configurado.",
24-
"07d84d34dd3a": "¡Simplemente agrega la directiva \"use i18n\" en la parte superior de tus archivos de componentes, y el compilador se encarga del resto!"
15+
"07d84d34dd3a": "¡Simplemente agrega la directiva \"use i18n\" en la parte superior de tus archivos de componentes, y el compilador se encarga del resto!",
16+
"daa4d8839395": "Clicado {counter} veces",
17+
"52ed9ee761d8": "Hola Mundo",
18+
"f11fc78c3ac0": "Contenido <b0>mixto</b0> <i0>fragmento</i0>",
19+
"556f5956dca7": "Bienvenido a la demo de Lingo.dev compiler",
20+
"02704ec4e52a": "Extrae automáticamente texto de tu JSX y lo traduce a otros idiomas.",
21+
"de6bfb30be49": "El texto insertado como <code0></code0> no se traduce: {text}",
22+
"5c15bd35e916": "Para traducirlo tienes que envolverlo en el '<'>{translatableText} '<'/>",
23+
"93b50fe805b7": "El texto externo al componente no se traduce: {externalText}",
24+
"d756b03ffbf5": "El contenido que tiene texto y otras etiquetas dentro se traducirá como una sola entidad: {translatableMixedContextFragment}"
2525
}
2626
}

‎demo/new-compiler-vite-react-spa/public/translations/fr.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"version": 0.1,
33
"locale": "fr",
44
"entries": {
5-
"daa4d8839395": "Cliqué {counter} fois",
6-
"52ed9ee761d8": "Bonjour le monde",
7-
"f11fc78c3ac0": "<b0>Contenu</b0> mixte <i0>fragment</i0>",
8-
"556f5956dca7": "Bienvenue dans la démo du compilateur Lingo.dev",
9-
"02704ec4e52a": "Il extrait automatiquement le texte de votre JSX et le traduit dans d'autres langues.",
10-
"de6bfb30be49": "Le texte inséré comme un <code0></code0> n'est pas traduit : {text}",
11-
"5c15bd35e916": "Pour le traduire, vous devez l'envelopper dans le '<'>{translatableText} '<'/>",
12-
"93b50fe805b7": "Le texte externe au composant n'est pas traduit : {externalText}",
13-
"d756b03ffbf5": "Le contenu qui contient du texte et d'autres balises sera traduit comme une seule entité : {translatableMixedContextFragment}",
145
"8492c53cfbaf": "À propos de Lingo.dev",
156
"8aa4fe3f0590": "Ceci est une application de démonstration présentant le compilateur Lingo.dev pour les traductions automatiques dans les applications React.",
167
"af76f667703b": "Fonctionnalités clés",
@@ -21,6 +12,15 @@
2112
"aca12d550fe2": "Prise en charge des composants serveur et client",
2213
"44a3311c3a4a": "Comment ça fonctionne",
2314
"0add30e37450": "Le compilateur analyse vos composants React au moment de la compilation et extrait automatiquement toutes les chaînes traduisibles. Il génère ensuite des traductions en utilisant votre fournisseur de traduction configuré.",
24-
"07d84d34dd3a": "Ajoutez simplement la directive \"use i18n\" en haut de vos fichiers de composants, et le compilateur s'occupe du reste !"
15+
"07d84d34dd3a": "Ajoutez simplement la directive \"use i18n\" en haut de vos fichiers de composants, et le compilateur s'occupe du reste !",
16+
"daa4d8839395": "Cliqué {counter} fois",
17+
"52ed9ee761d8": "Bonjour le monde",
18+
"f11fc78c3ac0": "<b0>Contenu</b0> mixte <i0>fragment</i0>",
19+
"556f5956dca7": "Bienvenue dans la démo du compilateur Lingo.dev",
20+
"02704ec4e52a": "Il extrait automatiquement le texte de votre JSX et le traduit dans d'autres langues.",
21+
"de6bfb30be49": "Le texte inséré comme un <code0></code0> n'est pas traduit : {text}",
22+
"5c15bd35e916": "Pour le traduire, vous devez l'envelopper dans le '<'>{translatableText} '<'/>",
23+
"93b50fe805b7": "Le texte externe au composant n'est pas traduit : {externalText}",
24+
"d756b03ffbf5": "Le contenu qui contient du texte et d'autres balises sera traduit comme une seule entité : {translatableMixedContextFragment}"
2525
}
2626
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pkg from "node-machine-id";
22
const { machineIdSync } = pkg;
33
import https from "https";
4-
import { getRepositoryId } from "./repository-id";
4+
import { getOrgId } from "./org-id";
55

66
const POSTHOG_API_KEY = "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk";
77
const POSTHOG_HOST = "eu.i.posthog.com";
@@ -12,23 +12,23 @@ const TRACKING_VERSION = "2.0";
1212
function determineDistinctId(email: string | null | undefined): {
1313
distinct_id: string;
1414
distinct_id_source: string;
15-
project_id: string | null;
15+
org_id: string | null;
1616
} {
17+
const orgId = getOrgId();
18+
1719
if (email) {
18-
const projectId = getRepositoryId();
1920
return {
2021
distinct_id: email,
2122
distinct_id_source: "email",
22-
project_id: projectId,
23+
org_id: orgId,
2324
};
2425
}
2526

26-
const repoId = getRepositoryId();
27-
if (repoId) {
27+
if (orgId) {
2828
return {
29-
distinct_id: repoId,
30-
distinct_id_source: "git_repo",
31-
project_id: repoId,
29+
distinct_id: orgId,
30+
distinct_id_source: "git_org",
31+
org_id: orgId,
3232
};
3333
}
3434

@@ -41,7 +41,7 @@ function determineDistinctId(email: string | null | undefined): {
4141
return {
4242
distinct_id: deviceId,
4343
distinct_id_source: "device",
44-
project_id: null,
44+
org_id: null,
4545
};
4646
}
4747

@@ -74,7 +74,7 @@ export default function trackEvent(
7474
$lib_version: process.env.npm_package_version || "unknown",
7575
tracking_version: TRACKING_VERSION,
7676
distinct_id_source: identityInfo.distinct_id_source,
77-
project_id: identityInfo.project_id,
77+
org_id: identityInfo.org_id,
7878
node_version: process.version,
7979
is_ci: !!process.env.CI,
8080
debug_enabled: process.env.DEBUG === "true",
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,115 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2-
import { getRepositoryId, clearRepositoryIdCache } from "./repository-id";
2+
import { getOrgId, clearOrgIdCache } from "./org-id";
33
import { execSync } from "child_process";
44

55
vi.mock("child_process");
66

7-
describe("getRepositoryId", () => {
7+
describe("getOrgId", () => {
88
const originalEnv = process.env;
99

1010
beforeEach(() => {
1111
process.env = { ...originalEnv };
1212
vi.clearAllMocks();
13-
clearRepositoryIdCache(); // Clear cache between tests
13+
clearOrgIdCache(); // Clear cache between tests
1414
});
1515

1616
afterEach(() => {
1717
process.env = originalEnv;
1818
});
1919

2020
describe("CI environment variables", () => {
21-
it("should detect GitHub repository from GITHUB_REPOSITORY", () => {
21+
it("should detect GitHub org from GITHUB_REPOSITORY", () => {
2222
process.env.GITHUB_REPOSITORY = "owner/repo";
23-
expect(getRepositoryId()).toBe("github:owner/071ca222");
23+
expect(getOrgId()).toBe("github:owner");
2424
});
2525

26-
it("should detect GitLab repository from CI_PROJECT_PATH", () => {
26+
it("should detect GitLab org from CI_PROJECT_PATH", () => {
2727
process.env.CI_PROJECT_PATH = "namespace/project";
28-
expect(getRepositoryId()).toBe("gitlab:namespace/244210e4");
28+
expect(getOrgId()).toBe("gitlab:namespace");
2929
});
3030

31-
it("should detect Bitbucket repository from BITBUCKET_REPO_FULL_NAME", () => {
31+
it("should detect Bitbucket org from BITBUCKET_REPO_FULL_NAME", () => {
3232
process.env.BITBUCKET_REPO_FULL_NAME = "workspace/repo";
33-
expect(getRepositoryId()).toBe("bitbucket:workspace/071ca222");
33+
expect(getOrgId()).toBe("bitbucket:workspace");
3434
});
3535

3636
it("should prioritize CI environment variables over git remote", () => {
3737
process.env.GITHUB_REPOSITORY = "owner/repo";
3838
vi.mocked(execSync).mockReturnValue(
3939
"git@gitlab.com:other/project.git" as any,
4040
);
41-
expect(getRepositoryId()).toBe("github:owner/071ca222");
41+
expect(getOrgId()).toBe("github:owner");
4242
});
4343
});
4444

4545
describe("git remote URL parsing", () => {
4646
it("should parse GitHub SSH URL", () => {
4747
vi.mocked(execSync).mockReturnValue("git@github.com:owner/repo.git" as any);
48-
expect(getRepositoryId()).toBe("github:owner/071ca222");
48+
expect(getOrgId()).toBe("github:owner");
4949
});
5050

5151
it("should parse GitHub HTTPS URL", () => {
5252
vi.mocked(execSync).mockReturnValue(
5353
"https://github.com/owner/repo.git" as any,
5454
);
55-
expect(getRepositoryId()).toBe("github:owner/071ca222");
55+
expect(getOrgId()).toBe("github:owner");
5656
});
5757

5858
it("should parse GitLab SSH URL", () => {
5959
vi.mocked(execSync).mockReturnValue(
6060
"git@gitlab.com:namespace/project.git" as any,
6161
);
62-
expect(getRepositoryId()).toBe("gitlab:namespace/244210e4");
62+
expect(getOrgId()).toBe("gitlab:namespace");
6363
});
6464

6565
it("should parse GitLab HTTPS URL", () => {
6666
vi.mocked(execSync).mockReturnValue(
6767
"https://gitlab.com/namespace/project.git" as any,
6868
);
69-
expect(getRepositoryId()).toBe("gitlab:namespace/244210e4");
69+
expect(getOrgId()).toBe("gitlab:namespace");
7070
});
7171

7272
it("should parse Bitbucket SSH URL", () => {
7373
vi.mocked(execSync).mockReturnValue(
7474
"git@bitbucket.org:workspace/repo.git" as any,
7575
);
76-
expect(getRepositoryId()).toBe("bitbucket:workspace/071ca222");
76+
expect(getOrgId()).toBe("bitbucket:workspace");
7777
});
7878

7979
it("should parse Bitbucket HTTPS URL", () => {
8080
vi.mocked(execSync).mockReturnValue(
8181
"https://bitbucket.org/workspace/repo.git" as any,
8282
);
83-
expect(getRepositoryId()).toBe("bitbucket:workspace/071ca222");
83+
expect(getOrgId()).toBe("bitbucket:workspace");
8484
});
8585

8686
it("should parse self-hosted git URL with generic prefix", () => {
8787
vi.mocked(execSync).mockReturnValue(
8888
"git@custom-git.company.com:team/project.git" as any,
8989
);
90-
expect(getRepositoryId()).toBe("git:team/244210e4");
90+
expect(getOrgId()).toBe("git:team");
9191
});
9292

9393
it("should handle URLs without .git extension", () => {
9494
vi.mocked(execSync).mockReturnValue("git@github.com:owner/repo" as any);
95-
expect(getRepositoryId()).toBe("github:owner/071ca222");
95+
expect(getOrgId()).toBe("github:owner");
9696
});
9797

9898
it("should return null when git command fails", () => {
9999
vi.mocked(execSync).mockImplementation(() => {
100100
throw new Error("not a git repository");
101101
});
102-
expect(getRepositoryId()).toBe(null);
102+
expect(getOrgId()).toBe(null);
103103
});
104104

105105
it("should return null when git remote is empty", () => {
106106
vi.mocked(execSync).mockReturnValue("" as any);
107-
expect(getRepositoryId()).toBe(null);
107+
expect(getOrgId()).toBe(null);
108108
});
109109

110110
it("should return null when git remote URL is invalid", () => {
111111
vi.mocked(execSync).mockReturnValue("invalid-url" as any);
112-
expect(getRepositoryId()).toBe(null);
112+
expect(getOrgId()).toBe(null);
113113
});
114114
});
115115
});

0 commit comments

Comments
 (0)