@devries-cameron20 / t3code Mirror · read-only / commits / 42da166d13
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 23, 13:00 UTC

fix(server): OTLP exports say which machine and build they came from (#19370)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 15, 2026 at 06:08 UTC 42da166d131017335a1158d0b379dd68b8985796
5 files changed +38 -4
apps/desktop/src/app/DesktopObservability.ts
+5
@@ -4,6 +4,7 @@ import {
4 makeTraceSink,
5 type SignalExport,
6 } from "@t3tools/shared/observability";
7 +import * as HostProcess from "@t3tools/shared/HostProcess";
8 import * as SharedObservability from "@t3tools/shared/observability";
9 import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
10 import {
@@ -625,12 +626,16 @@ const layerTelemetry = Layer.unwrap(
626 Effect.gen(function* () {
627 const environment = yield* DesktopEnvironment.DesktopEnvironment;
628 const endpoints = yield* resolveOtlpEndpoints;
629 + // `host.name` keeps machines apart on a shared collector; one set in
630 + // `OTEL_RESOURCE_ATTRIBUTES` wins, since explicit attributes override it.
631 const resource = {
632 serviceName: "t3code-desktop",
633 + serviceVersion: environment.appVersion,
634 attributes: {
635 "service.namespace": "t3code",
636 "service.runtime": "desktop",
637 "service.mode": environment.isDevelopment ? "development" : "packaged",
638 + "host.name": endpoints.resourceAttributes["host.name"] || (yield* HostProcess.Hostname),
639 },
640 };
641
apps/server/src/config.test.ts new
+18
@@ -0,0 +1,18 @@
1 +import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
2 +import { assert, describe, it } from "@effect/vitest";
3 +
4 +import * as ServerConfig from "./config.ts";
5 +
6 +describe("otlpResource", () => {
7 + const resource = (resourceAttributes: Record<string, string>) =>
8 + ServerConfig.otlpResource(
9 + { mode: "web", otelEnvironment: { ...OtelEnvironment.none, resourceAttributes } },
10 + "box-1",
11 + );
12 +
13 + it("names the host, unless OTEL_RESOURCE_ATTRIBUTES already does", () => {
14 + assert.equal(resource({}).attributes["host.name"], "box-1");
15 + assert.equal(resource({ "host.name": "from-env" }).attributes["host.name"], "from-env");
16 + assert.equal(resource({ "host.name": "" }).attributes["host.name"], "box-1");
17 + });
18 +});
apps/server/src/config.ts
+10 -2
@@ -19,6 +19,7 @@ import * as Schema from "effect/Schema";
19 import { sweepStalePendingAttachments } from "./attachmentStore.ts";
20 import { DEFAULT_SIGNAL_EXPORT, type SignalExport } from "@t3tools/shared/observability";
21 import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
22 +import packageJson from "../package.json" with { type: "json" };
23
24 export const DEFAULT_PORT = 3773;
25
@@ -118,14 +119,21 @@ export const make = (config: ServerConfig["Service"]) => ServerConfig.of(config)
119
120 /**
121 * Resource attributes shared by every OTLP exporter, so traces, metrics, and
121 - * logs report the same service identity to the collector.
122 + * logs report the same service identity to the collector. `host.name` keeps
123 + * servers apart when several export to one collector; a `host.name` set in
124 + * `OTEL_RESOURCE_ATTRIBUTES` wins, since explicit attributes override it.
125 */
123 -export const otlpResource = (config: ServerConfig["Service"]) => ({
126 +export const otlpResource = (
127 + config: Pick<ServerConfig["Service"], "mode" | "otelEnvironment">,
128 + hostName: string,
129 +) => ({
130 serviceName: "t3code-server",
131 + serviceVersion: packageJson.version,
132 attributes: {
133 "service.namespace": "t3code",
134 "service.runtime": "t3-server",
135 "service.mode": config.mode,
136 + "host.name": config.otelEnvironment.resourceAttributes["host.name"] || hostName,
137 },
138 });
139
apps/server/src/observability/Observability.ts
+2 -1
@@ -1,3 +1,4 @@
1 +import * as HostProcess from "@t3tools/shared/HostProcess";
2 import * as HttpObservability from "@t3tools/shared/httpObservability";
3 import { makeLocalFileTracer, makeTraceSink } from "@t3tools/shared/observability";
4 import * as SharedObservability from "@t3tools/shared/observability";
@@ -25,7 +26,7 @@ export const layer = Layer.unwrap(
26 // The trace serializer stays in the returned context because the browser
27 // trace forwarder exports on the same signal.
28 const layerSerialization = SharedObservability.layerOtlpSerialization(traces.protocol);
28 - const resource = ServerConfig.otlpResource(config);
29 + const resource = ServerConfig.otlpResource(config, yield* HostProcess.Hostname);
30 const attribution = yield* ResourceAttribution.ResourceAttribution;
31
32 const layerTraceReferences = Layer.mergeAll(
apps/server/src/serverLogger.ts
+3 -1
@@ -1,3 +1,4 @@
1 +import * as HostProcess from "@t3tools/shared/HostProcess";
2 import * as SharedObservability from "@t3tools/shared/observability";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
@@ -10,6 +11,7 @@ import * as ServerConfig from "./config.ts";
11
12 export const layer = Effect.gen(function* () {
13 const config = yield* ServerConfig.ServerConfig;
14 + const hostName = yield* HostProcess.Hostname;
15 const layerMinimumLogLevel = Layer.succeed(References.MinimumLogLevel, config.logLevel);
16
17 const logs = config.otlpLogsExport;
@@ -20,7 +22,7 @@ export const layer = Effect.gen(function* () {
22 url: config.otlpLogsUrl,
23 exportInterval: `${logs.exportIntervalMs} millis`,
24 headers: logs.headers,
23 - resource: ServerConfig.otlpResource(config),
25 + resource: ServerConfig.otlpResource(config, hostName),
26 });
27
28 // `Logger.layer` writes the whole logger set rather than adding to it, so