@devries-cameron20 / t3code-1 / commits / fa1e171553
Fork 0

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

refactor(observability): hold OTLP export settings per signal (#12657)

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

Yordis Prieto committed Sep 20, 2026 at 15:56 UTC fa1e1715538f6f8ac076761f7821f68479f616ab
12 files changed +104 -49
apps/server/src/bin.test.ts
+4 -3
@@ -15,6 +15,7 @@ import {
15 } from "@t3tools/contracts";
16 import * as NetService from "@t3tools/shared/Net";
17 import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";
18 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
19 import { assert, it } from "@effect/vitest";
20 import * as Effect from "effect/Effect";
21 import * as DateTime from "effect/DateTime";
@@ -101,10 +102,10 @@ const makeCliTestServerConfig = (baseDir: string) =>
102 otlpTracesUrl: undefined,
103 otlpMetricsUrl: undefined,
104 otlpLogsUrl: undefined,
104 - otlpExportIntervalMs: 10_000,
105 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
106 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
107 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
108 otlpServiceName: "t3-server",
106 - otlpHeaders: undefined,
107 - otlpProtocol: "http/json",
109 mode: "web",
110 port: 0,
111 host: "127.0.0.1",
apps/server/src/cli/config.test.ts
+12 -7
@@ -17,6 +17,7 @@ import {
17 type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
18 } from "@t3tools/contracts";
19 import * as NetService from "@t3tools/shared/Net";
20 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
21 import * as NodeServices from "@effect/platform-node/NodeServices";
22 import { deriveServerPaths } from "../config.ts";
23 import { resolveServerConfig } from "./config.ts";
@@ -51,10 +52,10 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
52 otlpTracesUrl: undefined,
53 otlpMetricsUrl: undefined,
54 otlpLogsUrl: undefined,
54 - otlpExportIntervalMs: 10_000,
55 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
56 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
57 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
58 otlpServiceName: "t3-server",
56 - otlpHeaders: undefined,
57 - otlpProtocol: "http/json",
59 devAllowedOrigins: [],
60 } as const;
61
@@ -764,7 +765,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
765 ),
766 );
767
767 - expect(resolved.otlpHeaders).toEqual({
768 + expect(resolved.otlpTracesExport.headers).toEqual({
769 authorization: "Basic abc==",
770 "x-tenant": "t3",
771 });
@@ -808,7 +809,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
809 ),
810 );
811
811 - expect(resolved.otlpHeaders).toEqual({
812 + expect(resolved.otlpTracesExport.headers).toEqual({
813 authorization: "Bearer abc==",
814 "x-tenant": "t3",
815 });
@@ -816,7 +817,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
817 }),
818 );
819
819 - it.effect("reads the OTLP protocol from env", () =>
820 + it.effect("gives every signal the protocol named without one", () =>
821 Effect.gen(function* () {
822 const { join } = yield* Path.Path;
823 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-otlp-protocol-base");
@@ -848,7 +849,11 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
849 ),
850 );
851
851 - expect(resolved.otlpProtocol).toBe("http/protobuf");
852 + expect([
853 + resolved.otlpTracesExport.protocol,
854 + resolved.otlpMetricsExport.protocol,
855 + resolved.otlpLogsExport.protocol,
856 + ]).toEqual(["http/protobuf", "http/protobuf", "http/protobuf"]);
857 }),
858 );
859
apps/server/src/cli/config.ts
+16 -4
@@ -1,5 +1,9 @@
1 import * as NetService from "@t3tools/shared/Net";
2 -import { OtlpHeadersFromString, OtlpProtocol } from "@t3tools/shared/observability";
2 +import {
3 + OtlpHeadersFromString,
4 + OtlpProtocol,
5 + type SignalExport,
6 +} from "@t3tools/shared/observability";
7 import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
8 import { DesktopBackendBootstrap, PortSchema } from "@t3tools/contracts";
9 import * as Config from "effect/Config";
@@ -382,6 +386,14 @@ export const resolveServerConfig = (
386 );
387 const logLevel = Option.getOrElse(cliLogLevel, () => env.logLevel);
388
389 + // T3 Code's own OTLP variables name no signal, so the one answer they give
390 + // is the answer for all three.
391 + const signalExport: SignalExport = {
392 + protocol: env.otlpProtocol,
393 + headers: env.otlpHeaders,
394 + exportIntervalMs: env.otlpExportIntervalMs,
395 + };
396 +
397 const config: ServerConfig.ServerConfig["Service"] = {
398 logLevel,
399 traceMinLevel: env.traceMinLevel,
@@ -399,10 +411,10 @@ export const resolveServerConfig = (
411 persistedObservabilitySettings.otlpMetricsUrl,
412 otlpLogsUrl:
413 env.otlpLogsUrl ?? bootstrap?.otlpLogsUrl ?? persistedObservabilitySettings.otlpLogsUrl,
402 - otlpExportIntervalMs: env.otlpExportIntervalMs,
414 + otlpTracesExport: signalExport,
415 + otlpMetricsExport: signalExport,
416 + otlpLogsExport: signalExport,
417 otlpServiceName: env.otlpServiceName,
404 - otlpHeaders: env.otlpHeaders,
405 - otlpProtocol: env.otlpProtocol,
418 mode,
419 port,
420 cwd,
apps/server/src/cli/pair.ts
+4 -3
@@ -15,6 +15,7 @@ import {
15 PortSchema,
16 } from "@t3tools/contracts";
17 import { resolveWorktreeT3Home } from "@t3tools/shared/devHome";
18 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
19 import {
20 buildTailscaleHttpsBaseUrl,
21 DEFAULT_TAILSCALE_SERVE_PORT,
@@ -321,10 +322,10 @@ const makePairServerConfig = Effect.fn(function* (input: {
322 otlpTracesUrl: undefined,
323 otlpMetricsUrl: undefined,
324 otlpLogsUrl: undefined,
324 - otlpExportIntervalMs: 10_000,
325 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
326 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
327 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
328 otlpServiceName: "t3-server",
326 - otlpHeaders: undefined,
327 - otlpProtocol: "http/json",
329 mode: "web",
330 port: state.port,
331 host: state.host,
apps/server/src/config.ts
+12 -7
@@ -17,7 +17,7 @@ import type * as Redacted from "effect/Redacted";
17 import * as Schema from "effect/Schema";
18
19 import { sweepStalePendingAttachments } from "./attachmentStore.ts";
20 -import { OtlpProtocol } from "@t3tools/shared/observability";
20 +import { DEFAULT_SIGNAL_EXPORT, type SignalExport } from "@t3tools/shared/observability";
21
22 export const DEFAULT_PORT = 3773;
23
@@ -73,10 +73,15 @@ export class ServerConfig extends Context.Service<
73 readonly otlpTracesUrl: string | undefined;
74 readonly otlpMetricsUrl: string | undefined;
75 readonly otlpLogsUrl: string | undefined;
76 - readonly otlpExportIntervalMs: number;
76 + /**
77 + * How each signal is exported. Read instead of a process-wide setting so
78 + * the wire format, credential, and schedule travel with the endpoint they
79 + * were configured beside.
80 + */
81 + readonly otlpTracesExport: SignalExport;
82 + readonly otlpMetricsExport: SignalExport;
83 + readonly otlpLogsExport: SignalExport;
84 readonly otlpServiceName: string;
78 - readonly otlpHeaders: Readonly<Record<string, string>> | undefined;
79 - readonly otlpProtocol: OtlpProtocol;
85 readonly mode: RuntimeMode;
86 readonly port: number;
87 readonly host: string | undefined;
@@ -212,10 +217,10 @@ const makeTest = Effect.fn("ServerConfig.makeTest")(function* (
217 otlpTracesUrl: undefined,
218 otlpMetricsUrl: undefined,
219 otlpLogsUrl: undefined,
215 - otlpExportIntervalMs: 10_000,
220 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
221 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
222 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
223 otlpServiceName: "t3-server",
217 - otlpHeaders: undefined,
218 - otlpProtocol: "http/json",
224 cwd,
225 baseDir,
226 ...derivedPaths,
apps/server/src/environment/ServerEnvironment.test.ts
+5 -3
@@ -10,6 +10,8 @@ import * as Option from "effect/Option";
10 import * as PlatformError from "effect/PlatformError";
11 import * as Schema from "effect/Schema";
12
13 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
14 +
15 import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
16 import {
17 PUBLISH_AGENT_ACTIVITY_SECRET,
@@ -54,10 +56,10 @@ const makeServerConfig = Effect.fn(function* (baseDir: string) {
56 otlpTracesUrl: undefined,
57 otlpMetricsUrl: undefined,
58 otlpLogsUrl: undefined,
57 - otlpExportIntervalMs: 10_000,
59 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
60 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
61 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
62 otlpServiceName: "t3-server",
59 - otlpHeaders: undefined,
60 - otlpProtocol: "http/json",
63 cwd: process.cwd(),
64 baseDir,
65 mode: "web",
apps/server/src/http.ts
+1 -1
@@ -322,7 +322,7 @@ export const otlpTracesProxyRouteLayer = HttpRouter.add(
322 const request = yield* HttpServerRequest.HttpServerRequest;
323 const config = yield* ServerConfig.ServerConfig;
324 const otlpTracesUrl = config.otlpTracesUrl;
325 - const otlpHeaders = config.otlpHeaders;
325 + const otlpHeaders = config.otlpTracesExport.headers;
326 const browserTraceCollector = yield* BrowserTraceCollector.BrowserTraceCollector;
327 const httpClient = yield* HttpClient.HttpClient;
328 const serialization = yield* OtlpSerialization.OtlpSerialization;
apps/server/src/observability/Layers/Observability.ts
+10 -6
@@ -20,7 +20,11 @@ import * as BrowserTraceCollector from "../BrowserTraceCollector.ts";
20 export const ObservabilityLive = Layer.unwrap(
21 Effect.gen(function* () {
22 const config = yield* ServerConfig.ServerConfig;
23 - const serializationLayer = otlpSerializationLayer(config.otlpProtocol);
23 + const traces = config.otlpTracesExport;
24 + const metrics = config.otlpMetricsExport;
25 + // The trace serializer stays in the returned context because the browser
26 + // trace forwarder exports on the same signal.
27 + const serializationLayer = otlpSerializationLayer(traces.protocol);
28 const resource = ServerConfig.otlpResource(config);
29 const attribution = yield* ResourceAttribution.ResourceAttribution;
30
@@ -51,8 +55,8 @@ export const ObservabilityLive = Layer.unwrap(
55 ? undefined
56 : yield* OtlpTracer.make({
57 url: config.otlpTracesUrl,
54 - exportInterval: `${config.otlpExportIntervalMs} millis`,
55 - headers: config.otlpHeaders,
58 + exportInterval: `${traces.exportIntervalMs} millis`,
59 + headers: traces.headers,
60 resource,
61 });
62
@@ -77,10 +81,10 @@ export const ObservabilityLive = Layer.unwrap(
81 ? Layer.empty
82 : OtlpMetrics.layer({
83 url: config.otlpMetricsUrl,
80 - exportInterval: `${config.otlpExportIntervalMs} millis`,
81 - headers: config.otlpHeaders,
84 + exportInterval: `${metrics.exportIntervalMs} millis`,
85 + headers: metrics.headers,
86 resource,
83 - }).pipe(Layer.provideMerge(serializationLayer));
87 + }).pipe(Layer.provide(otlpSerializationLayer(metrics.protocol)));
88
89 return Layer.mergeAll(ServerLoggerLive, traceReferencesLayer, tracerLayer, metricsLayer);
90 }),
apps/server/src/server.test.ts
+6 -6
@@ -218,7 +218,7 @@ import {
218 transferBudgetViolations,
219 } from "../integration/TransferBudgetReport.integration.ts";
220 import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
221 -import { otlpSerializationLayer } from "@t3tools/shared/observability";
221 +import { DEFAULT_SIGNAL_EXPORT, otlpSerializationLayer } from "@t3tools/shared/observability";
222
223 const defaultProjectId = ProjectId.make("project-default");
224 const defaultThreadId = ThreadId.make("thread-default");
@@ -578,10 +578,10 @@ const buildAppUnderTest = (options?: {
578 otlpTracesUrl: undefined,
579 otlpMetricsUrl: undefined,
580 otlpLogsUrl: undefined,
581 - otlpExportIntervalMs: 10_000,
581 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
582 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
583 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
584 otlpServiceName: "t3-server",
583 - otlpHeaders: undefined,
584 - otlpProtocol: "http/json",
585 mode: "desktop",
586 port: 0,
587 host: "127.0.0.1",
@@ -1076,7 +1076,7 @@ const buildAppUnderTest = (options?: {
1076 ...options?.layers?.browserTraceCollector,
1077 }),
1078 ),
1079 - Layer.provide(otlpSerializationLayer(config.otlpProtocol)),
1079 + Layer.provide(otlpSerializationLayer(config.otlpTracesExport.protocol)),
1080 Layer.provide(
1081 Layer.mock(ServerLifecycleEvents.ServerLifecycleEvents)({
1082 publish: (event) => Effect.succeed({ ...(event as any), sequence: 1 }),
@@ -5299,7 +5299,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
5299 yield* buildAppUnderTest({
5300 config: {
5301 otlpTracesUrl: collector.url,
5302 - otlpProtocol: "http/protobuf",
5302 + otlpTracesExport: { ...DEFAULT_SIGNAL_EXPORT, protocol: "http/protobuf" },
5303 },
5304 layers: {
5305 browserTraceCollector: {
apps/server/src/serverLogger.test.ts
+11 -6
@@ -8,6 +8,8 @@ import * as Tracer from "effect/Tracer";
8 import * as HttpClient from "effect/unstable/http/HttpClient";
9 import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
10
11 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
12 +
13 import * as ServerConfig from "./config.ts";
14 import { ServerLoggerLive } from "./serverLogger.ts";
15
@@ -51,10 +53,10 @@ const configLayer = (overrides: Partial<ServerConfig.ServerConfig["Service"]>) =
53 otlpTracesUrl: undefined,
54 otlpMetricsUrl: undefined,
55 otlpLogsUrl: undefined,
54 - otlpExportIntervalMs: 10_000,
56 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
57 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
58 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
59 otlpServiceName: "t3-server",
56 - otlpHeaders: undefined,
57 - otlpProtocol: "http/json",
60 cwd: baseDir,
61 baseDir,
62 ...derivedPaths,
@@ -155,12 +157,15 @@ describe("ServerLoggerLive", () => {
157 }),
158 );
159
158 - it.effect("sends the headers and wire format the rest of OTLP export already uses", () =>
160 + it.effect("sends the headers and wire format the log signal asked for", () =>
161 Effect.gen(function* () {
162 const requests = yield* logThrough({
163 otlpLogsUrl: "https://collector.example.com/v1/logs",
162 - otlpProtocol: "http/protobuf",
163 - otlpHeaders: { "x-scope": "logs" },
164 + otlpLogsExport: {
165 + ...DEFAULT_SIGNAL_EXPORT,
166 + protocol: "http/protobuf",
167 + headers: { "x-scope": "logs" },
168 + },
169 });
170
171 assert.lengthOf(requests, 1);
apps/server/src/serverLogger.ts
+4 -3
@@ -12,13 +12,14 @@ export const ServerLoggerLive = Effect.gen(function* () {
12 const config = yield* ServerConfig;
13 const minimumLogLevelLayer = Layer.succeed(References.MinimumLogLevel, config.logLevel);
14
15 + const logs = config.otlpLogsExport;
16 const otlpLogger =
17 config.otlpLogsUrl === undefined
18 ? undefined
19 : OtlpLogger.make({
20 url: config.otlpLogsUrl,
20 - exportInterval: `${config.otlpExportIntervalMs} millis`,
21 - headers: config.otlpHeaders,
21 + exportInterval: `${logs.exportIntervalMs} millis`,
22 + headers: logs.headers,
23 resource: otlpResource(config),
24 });
25
@@ -41,7 +42,7 @@ export const ServerLoggerLive = Effect.gen(function* () {
42 { mergeWithExisting: false },
43 ).pipe(
44 Layer.provide(OtlpExporter.layerFlusher),
44 - Layer.provide(otlpSerializationLayer(config.otlpProtocol)),
45 + Layer.provide(otlpSerializationLayer(logs.protocol)),
46 );
47
48 return Layer.mergeAll(loggerLayer, minimumLogLevelLayer);
packages/shared/src/observability.ts
+19
@@ -16,6 +16,25 @@ export type OtlpProtocol = typeof OtlpProtocol.Type;
16 export const otlpSerializationLayer = (protocol: OtlpProtocol) =>
17 protocol === "http/protobuf" ? OtlpSerialization.layerProtobuf : OtlpSerialization.layerJson;
18
19 +/**
20 + * How one signal is exported, once whichever source named that signal's
21 + * endpoint has been resolved. Held per signal rather than per process, so a
22 + * wire format or a credential cannot be paired by hand with an endpoint that
23 + * came from somewhere else.
24 + */
25 +export interface SignalExport {
26 + readonly protocol: OtlpProtocol;
27 + readonly headers: Readonly<Record<string, string>> | undefined;
28 + readonly exportIntervalMs: number;
29 +}
30 +
31 +/** What T3 Code exports with when nothing configured a signal. */
32 +export const DEFAULT_SIGNAL_EXPORT: SignalExport = {
33 + protocol: "http/json",
34 + headers: undefined,
35 + exportIntervalMs: 10_000,
36 +};
37 +
38 const FLUSH_BUFFER_THRESHOLD = 256;
39 const textEncoder = new TextEncoder();
40