@devries-cameron20 / t3code Mirror · read-only / commits / 20ee805de9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 17:00 UTC

fix(observability): resources add OTel semconv runtime and browser keys (#23972)

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Yordis Prieto committed Oct 25, 2026 at 18:11 UTC 20ee805de9ee5b911ac2fd586c197dcc0e9a63e0
7 files changed +87 -3
apps/desktop/src/app/DesktopObservability.test.ts
+32
@@ -342,4 +342,36 @@ describe("DesktopObservability", () => {
342 Effect.provide(Layer.mergeAll(NodeServices.layer, layerCollector(requests), layerEmptyEnv)),
343 );
344 });
345 +
346 + it.effect("describes the Node runtime and the desktop mode under semantic or t3code keys", () => {
347 + const requests: Array<ExportedRequest> = [];
348 + return Effect.gen(function* () {
349 + const fileSystem = yield* FileSystem.FileSystem;
350 + const baseDir = yield* fileSystem.makeTempDirectoryScoped({
351 + prefix: "t3-desktop-observability-test-",
352 + });
353 + const layerEnvironment = layerEnvironmentFor(baseDir);
354 + yield* writeObservabilitySettings(layerEnvironment, {
355 + otlpLogsUrl: "https://settings.example.com/v1/logs",
356 + });
357 +
358 + yield* Effect.scoped(
359 + Effect.logInfo("desktop resource under test").pipe(
360 + Effect.provide(DesktopObservability.layer.pipe(Layer.provideMerge(layerEnvironment))),
361 + ),
362 + );
363 +
364 + const body = requests.map((request) => request.body).join("\n");
365 + assert.include(body, '"key":"process.runtime.name","value":{"stringValue":"nodejs"}');
366 + assert.include(
367 + body,
368 + `"key":"process.runtime.version","value":{"stringValue":"${process.versions.node}"}`,
369 + );
370 + assert.include(body, '"key":"t3code.desktop.mode","value":{"stringValue":"development"}');
371 + assert.notInclude(body, "service.mode");
372 + }).pipe(
373 + Effect.scoped,
374 + Effect.provide(Layer.mergeAll(NodeServices.layer, layerCollector(requests), layerEmptyEnv)),
375 + );
376 + });
377 });
apps/desktop/src/app/DesktopObservability.ts
+3 -1
@@ -2,6 +2,7 @@ import { PRIMARY_LOCAL_ENVIRONMENT_ID } from "@t3tools/contracts";
2 import {
3 makeLocalFileTracer,
4 makeTraceSink,
5 + nodeProcessRuntimeAttributes,
6 processServiceInstanceId,
7 type SignalExport,
8 } from "@t3tools/shared/observability";
@@ -607,13 +608,14 @@ const layerTelemetry = Layer.unwrap(
608 attributes: {
609 "service.namespace": "t3code",
610 "service.runtime": "desktop",
610 - "service.mode": environment.isDevelopment ? "development" : "packaged",
611 + "t3code.desktop.mode": environment.isDevelopment ? "development" : "packaged",
612 "service.instance.id": processServiceInstanceId(endpoints.resourceAttributes),
613 ...releaseResourceAttributes(
614 environment.isDevelopment ? "dev" : releaseChannelOf(serviceVersion),
615 endpoints.resourceAttributes,
616 ),
617 "host.name": endpoints.resourceAttributes["host.name"] || (yield* HostProcess.Hostname),
618 + ...nodeProcessRuntimeAttributes(),
619 },
620 };
621
apps/server/src/cloud/relayTracing.ts
+6 -1
@@ -1,4 +1,7 @@
1 -import { processServiceInstanceId } from "@t3tools/shared/observability";
1 +import {
2 + nodeProcessRuntimeAttributes,
3 + processServiceInstanceId,
4 +} from "@t3tools/shared/observability";
5 import * as RelayTracing from "@t3tools/shared/relayTracing";
6 import * as Effect from "effect/Effect";
7 import * as Layer from "effect/Layer";
@@ -21,12 +24,14 @@ const relayLayer = (resource: Omit<RelayTracing.RelayClientTracingResource, "ser
24 export const layerHeadlessRelayClient = relayLayer({
25 serviceName: "t3code-server",
26 runtime: "node",
27 + attributes: nodeProcessRuntimeAttributes(),
28 client: "headless-cli",
29 });
30
31 export const layerServerRelayBroker = relayLayer({
32 serviceName: "t3code-server",
33 runtime: "node",
34 + attributes: nodeProcessRuntimeAttributes(),
35 client: "environment-server",
36 component: "relay-broker",
37 });
apps/server/src/config.ts
+2
@@ -12,6 +12,7 @@ import type { OtlpEndpointSource } from "@t3tools/contracts";
12 import { sweepStalePendingAttachments } from "./attachmentStore.ts";
13 import {
14 DEFAULT_SIGNAL_EXPORT,
15 + nodeProcessRuntimeAttributes,
16 processServiceInstanceId,
17 type SignalExport,
18 } from "@t3tools/shared/observability";
@@ -128,6 +129,7 @@ export const otlpResource = (
129 "service.instance.id": processServiceInstanceId(config.otelEnvironment.resourceAttributes),
130 ...releaseResourceAttributes(telemetryChannel, config.otelEnvironment.resourceAttributes),
131 "host.name": config.otelEnvironment.resourceAttributes["host.name"] || hostName,
132 + ...nodeProcessRuntimeAttributes(),
133 },
134 });
135
apps/web/src/observability/clientTracing.ts
+27
@@ -15,6 +15,32 @@ import { isElectron } from "../env";
15 import { APP_VERSION } from "~/branding";
16
17 const DEFAULT_EXPORT_INTERVAL_MS = 1_000;
18 +interface NavigatorUserAgentData {
19 + readonly platform: string;
20 + readonly mobile: boolean;
21 + readonly brands: ReadonlyArray<{ readonly brand: string; readonly version: string }>;
22 +}
23 +
24 +/**
25 + * The `browser.*` and `user_agent.original` attributes the OpenTelemetry browser
26 + * resource detector reports. `userAgentData` exists only in Chromium, which
27 + * includes the desktop app.
28 + */
29 +const browserResourceAttributes = (): Record<string, unknown> => {
30 + if (typeof navigator === "undefined") return {};
31 + const userAgentData = (navigator as Navigator & { userAgentData?: NavigatorUserAgentData })
32 + .userAgentData;
33 + return {
34 + "user_agent.original": navigator.userAgent,
35 + "browser.language": navigator.language,
36 + ...(userAgentData && {
37 + "browser.platform": userAgentData.platform,
38 + "browser.mobile": userAgentData.mobile,
39 + "browser.brands": userAgentData.brands.map(({ brand, version }) => `${brand} ${version}`),
40 + }),
41 + };
42 +};
43 +
44 // PR previews can't mark themselves in APP_VERSION without breaking the version-skew check against the server.
45 const RELEASE_CHANNEL =
46 import.meta.env.DEV || import.meta.env.VITE_RELEASE_CHANNEL === "dev"
@@ -31,6 +57,7 @@ const CLIENT_TRACING_RESOURCE = {
57 "service.runtime": "t3-web",
58 "t3code.client.surface": isElectron ? "desktop" : "web",
59 "service.version": APP_VERSION,
60 + ...browserResourceAttributes(),
61 },
62 } as const;
63
docs/operations/observability.md
+5 -1
@@ -642,7 +642,11 @@ reports `dev` from a development bundle.
642 Attributes specific to T3 Code use the `t3code.` prefix. The UI runs as `t3code-web` in both a
643 browser and the desktop window, since it is the same code, and `t3code.client.surface` is `desktop`
644 or `web`. The server's `t3code.server.managed_by` is `desktop` when the desktop app launched it and
645 -`standalone` otherwise.
645 +`standalone` otherwise. The desktop main process reports `t3code.desktop.mode` as `development` or
646 +`packaged` (formerly `service.mode`; dashboards filtering on that key must switch). Node processes
647 +also report the semantic `process.runtime.name`, `process.runtime.version`, and
648 +`process.runtime.description`, and UI traces report `browser.language`, `user_agent.original`, and,
649 +in Chromium, `browser.platform`, `browser.mobile`, and `browser.brands`.
650
651 Every resource also carries a `service.instance.id`: random per process for the server and desktop,
652 per page load for the UI, and the Expo session on mobile. A `service.instance.id` in
packages/shared/src/observability.ts
+12
@@ -26,6 +26,18 @@ export interface SignalExport {
26 readonly exportIntervalMs: number;
27 }
28
29 +/**
30 + * `process.runtime.*` resource attributes for a Node process, matching the
31 + * OpenTelemetry Node process detector. Electron embeds Node, so an Electron
32 + * process reports Node and names Electron in the description.
33 + */
34 +export const nodeProcessRuntimeAttributes = (): Record<string, string> => ({
35 + "process.runtime.name": "nodejs",
36 + "process.runtime.version": process.versions.node,
37 + "process.runtime.description": process.versions.electron
38 + ? `Electron ${process.versions.electron}`
39 + : "Node.js",
40 +});
41 let generatedServiceInstanceId: string | undefined;
42
43 /**