The best way to control Claude Code, Codex and more from any computer or phone
Allow setting T3CODE_OTLP_HEADERS (#11218)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Arne Bahlo committed
Sep 14, 2026 at 19:46 UTC
494cfac2494095c3f9b24cc16fb73721f84894a4
19 files changed
+220
-3
apps/desktop/scripts/electron-launcher.mjs
+1
@@ -116,6 +116,7 @@ export function makeDevelopmentEnvironmentScript(environment) {
116
["T3CODE_COMMIT_HASH", environment.T3CODE_COMMIT_HASH],
117
["T3CODE_OTLP_TRACES_URL", environment.T3CODE_OTLP_TRACES_URL],
118
["T3CODE_OTLP_EXPORT_INTERVAL_MS", environment.T3CODE_OTLP_EXPORT_INTERVAL_MS],
119
+ ["T3CODE_OTLP_HEADERS", environment.T3CODE_OTLP_HEADERS],
120
["T3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
121
].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
122
return [
apps/desktop/src/app/DesktopConfig.ts
+2
@@ -1,3 +1,4 @@
1
+import { OtlpHeadersFromString } from "@t3tools/shared/observability";
2
import * as Config from "effect/Config";
3
import * as ConfigProvider from "effect/ConfigProvider";
4
import * as Option from "effect/Option";
@@ -48,6 +49,7 @@ export const DesktopConfig = Config.all({
49
otlpExportIntervalMs: Config.int("T3CODE_OTLP_EXPORT_INTERVAL_MS").pipe(
50
Config.withDefault(10_000),
51
),
52
+ otlpHeaders: Config.schema(OtlpHeadersFromString, "T3CODE_OTLP_HEADERS").pipe(Config.option),
53
appImagePath: trimmedString("APPIMAGE"),
54
disableAutoUpdate: optionalBoolean("T3CODE_DISABLE_AUTO_UPDATE"),
55
mockUpdates: optionalBoolean("T3CODE_DESKTOP_MOCK_UPDATES"),
apps/desktop/src/app/DesktopEnvironment.test.ts
+8
@@ -52,6 +52,7 @@ describe("DesktopEnvironment", () => {
52
T3CODE_DEV_REMOTE_T3_SERVER_ENTRY_PATH: " /remote/server.mjs ",
53
T3CODE_OTLP_TRACES_URL: " http://127.0.0.1:4318/v1/traces ",
54
T3CODE_OTLP_EXPORT_INTERVAL_MS: "2500",
55
+ T3CODE_OTLP_HEADERS: "authorization=Basic%20abc%3D%3D,x-tenant=t3",
56
},
57
);
58
@@ -85,6 +86,13 @@ describe("DesktopEnvironment", () => {
86
assert.deepEqual(environment.commitHashOverride, Option.some("0123456789abcdef"));
87
assert.deepEqual(environment.otlpTracesUrl, Option.some("http://127.0.0.1:4318/v1/traces"));
88
assert.equal(environment.otlpExportIntervalMs, 2500);
89
+ assert.deepEqual(
90
+ environment.otlpHeaders,
91
+ Option.some({
92
+ authorization: "Basic abc==",
93
+ "x-tenant": "t3",
94
+ }),
95
+ );
96
}),
97
);
98
apps/desktop/src/app/DesktopEnvironment.ts
+2
@@ -72,6 +72,7 @@ export class DesktopEnvironment extends Context.Service<
72
readonly commitHashOverride: Option.Option<string>;
73
readonly otlpTracesUrl: Option.Option<string>;
74
readonly otlpExportIntervalMs: number;
75
+ readonly otlpHeaders: Option.Option<Record<string, string>>;
76
readonly branding: DesktopAppBranding;
77
readonly displayName: string;
78
readonly appUserModelId: string;
@@ -225,6 +226,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
226
commitHashOverride: config.commitHashOverride,
227
otlpTracesUrl: config.otlpTracesUrl,
228
otlpExportIntervalMs: config.otlpExportIntervalMs,
229
+ otlpHeaders: config.otlpHeaders,
230
branding,
231
displayName,
232
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>
apps/desktop/src/app/DesktopObservability.ts
+1
@@ -584,6 +584,7 @@ const tracerLayer = Layer.unwrap(
584
: yield* OtlpTracer.make({
585
url: otlpTracesUrl.value,
586
exportInterval: `${environment.otlpExportIntervalMs} millis`,
587
+ headers: Option.getOrUndefined(environment.otlpHeaders),
588
resource: {
589
serviceName: "desktop",
590
attributes: {
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+4
-1
@@ -853,10 +853,12 @@ describe("DesktopBackendConfiguration", () => {
853
const previousWslEnv = process.env.WSLENV;
854
const previousOpenAiKey = process.env.OPENAI_API_KEY;
855
const previousAnthropicKey = process.env.ANTHROPIC_API_KEY;
856
+ const previousOtlpHeaders = process.env.T3CODE_OTLP_HEADERS;
857
try {
858
process.env.WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u";
859
process.env.OPENAI_API_KEY = "openai-key";
860
process.env.ANTHROPIC_API_KEY = "anthropic-key";
861
+ process.env.T3CODE_OTLP_HEADERS = 'authorization="Bearer%20my-token"';
862
863
yield* Effect.gen(function* () {
864
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
@@ -882,7 +884,7 @@ describe("DesktopBackendConfiguration", () => {
884
// already declared, so it isn't forwarded twice.
885
assert.equal(
886
config.env.WSLENV,
885
- "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY",
887
+ "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY:T3CODE_OTLP_HEADERS",
888
);
889
}).pipe(
890
Effect.provide(
@@ -905,6 +907,7 @@ describe("DesktopBackendConfiguration", () => {
907
restoreEnv("WSLENV", previousWslEnv);
908
restoreEnv("OPENAI_API_KEY", previousOpenAiKey);
909
restoreEnv("ANTHROPIC_API_KEY", previousAnthropicKey);
910
+ restoreEnv("T3CODE_OTLP_HEADERS", previousOtlpHeaders);
911
}
912
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
913
);
apps/desktop/src/backend/DesktopBackendConfiguration.ts
+5
-1
@@ -91,7 +91,11 @@ const DESKTOP_BACKEND_ENV_NAMES = [
91
// forward across the wsl.exe boundary without WSLENV. The dev-server URL is
92
// handled separately via a `--dev-url` CLI flag because WSLENV translation of
93
// URL-shaped values (colons / slashes) is unreliable.
94
-const WSL_FORWARDED_ENV_NAMES = ["OPENAI_API_KEY", "ANTHROPIC_API_KEY"] as const;
94
+const WSL_FORWARDED_ENV_NAMES = [
95
+ "OPENAI_API_KEY",
96
+ "ANTHROPIC_API_KEY",
97
+ "T3CODE_OTLP_HEADERS",
98
+] as const;
99
100
const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
101
apps/server/src/bin.test.ts
+1
@@ -101,6 +101,7 @@ const makeCliTestServerConfig = (baseDir: string) =>
101
otlpMetricsUrl: undefined,
102
otlpExportIntervalMs: 10_000,
103
otlpServiceName: "t3-server",
104
+ otlpHeaders: undefined,
105
mode: "web",
106
port: 0,
107
host: "127.0.0.1",
apps/server/src/cli/config.test.ts
+89
@@ -52,6 +52,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
52
otlpMetricsUrl: undefined,
53
otlpExportIntervalMs: 10_000,
54
otlpServiceName: "t3-server",
55
+ otlpHeaders: undefined,
56
devAllowedOrigins: [],
57
} as const;
58
@@ -719,4 +720,92 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
720
});
721
}),
722
);
723
+
724
+ it.effect("decodes percent-encoded OTLP headers from env", () =>
725
+ Effect.gen(function* () {
726
+ const { join } = yield* Path.Path;
727
+ const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-otlp-headers-base");
728
+
729
+ const resolved = yield* resolveServerConfig(
730
+ {
731
+ mode: Option.some("web"),
732
+ port: Option.some(3773),
733
+ host: Option.none(),
734
+ baseDir: Option.some(baseDir),
735
+ cwd: Option.none(),
736
+ devUrl: Option.none(),
737
+ noBrowser: Option.none(),
738
+ bootstrapFd: Option.none(),
739
+ autoBootstrapProjectFromCwd: Option.none(),
740
+ logWebSocketEvents: Option.none(),
741
+ tailscaleServeEnabled: Option.none(),
742
+ tailscaleServePort: Option.none(),
743
+ },
744
+ Option.none(),
745
+ ).pipe(
746
+ Effect.provide(
747
+ Layer.mergeAll(
748
+ ConfigProvider.layer(
749
+ ConfigProvider.fromEnv({
750
+ env: {
751
+ T3CODE_OTLP_HEADERS: "authorization=Basic%20abc%3D%3D,x-tenant=t3",
752
+ },
753
+ }),
754
+ ),
755
+ NetService.layer,
756
+ ),
757
+ ),
758
+ );
759
+
760
+ expect(resolved.otlpHeaders).toEqual({
761
+ authorization: "Basic abc==",
762
+ "x-tenant": "t3",
763
+ });
764
+ }),
765
+ );
766
+
767
+ it.effect("keeps whitespace-separated pairs and literal equals signs in OTLP headers", () =>
768
+ Effect.gen(function* () {
769
+ const { join } = yield* Path.Path;
770
+ const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-otlp-headers-loose-base");
771
+
772
+ const resolved = yield* resolveServerConfig(
773
+ {
774
+ mode: Option.some("web"),
775
+ port: Option.some(3773),
776
+ host: Option.none(),
777
+ baseDir: Option.some(baseDir),
778
+ cwd: Option.none(),
779
+ devUrl: Option.none(),
780
+ noBrowser: Option.none(),
781
+ bootstrapFd: Option.none(),
782
+ autoBootstrapProjectFromCwd: Option.none(),
783
+ logWebSocketEvents: Option.none(),
784
+ tailscaleServeEnabled: Option.none(),
785
+ tailscaleServePort: Option.none(),
786
+ },
787
+ Option.none(),
788
+ ).pipe(
789
+ Effect.provide(
790
+ Layer.mergeAll(
791
+ ConfigProvider.layer(
792
+ ConfigProvider.fromEnv({
793
+ env: {
794
+ T3CODE_OTLP_HEADERS: "authorization=Bearer abc==, x-tenant=t3",
795
+ T3CODE_OTLP_TRACES_URL: "http://collector.internal:4318",
796
+ },
797
+ }),
798
+ ),
799
+ NetService.layer,
800
+ ),
801
+ ),
802
+ );
803
+
804
+ expect(resolved.otlpHeaders).toEqual({
805
+ authorization: "Bearer abc==",
806
+ "x-tenant": "t3",
807
+ });
808
+ expect(resolved.otlpTracesUrl).toBe("http://collector.internal:4318");
809
+ }),
810
+ );
811
});
apps/server/src/cli/config.ts
+6
@@ -1,4 +1,5 @@
1
import * as NetService from "@t3tools/shared/Net";
2
+import { OtlpHeadersFromString } from "@t3tools/shared/observability";
3
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
4
import { DesktopBackendBootstrap, PortSchema } from "@t3tools/contracts";
5
import * as Config from "effect/Config";
@@ -99,6 +100,10 @@ const EnvServerConfig = Config.all({
100
Config.withDefault(10_000),
101
),
102
otlpServiceName: Config.string("T3CODE_OTLP_SERVICE_NAME").pipe(Config.withDefault("t3-server")),
103
+ otlpHeaders: Config.schema(OtlpHeadersFromString, "T3CODE_OTLP_HEADERS").pipe(
104
+ Config.option,
105
+ Config.map(Option.getOrUndefined),
106
+ ),
107
mode: Config.schema(ServerConfig.RuntimeMode, "T3CODE_MODE").pipe(
108
Config.option,
109
Config.map(Option.getOrUndefined),
@@ -387,6 +392,7 @@ export const resolveServerConfig = (
392
persistedObservabilitySettings.otlpMetricsUrl,
393
otlpExportIntervalMs: env.otlpExportIntervalMs,
394
otlpServiceName: env.otlpServiceName,
395
+ otlpHeaders: env.otlpHeaders,
396
mode,
397
port,
398
cwd,
apps/server/src/cli/pair.ts
+1
@@ -322,6 +322,7 @@ const makePairServerConfig = Effect.fn(function* (input: {
322
otlpMetricsUrl: undefined,
323
otlpExportIntervalMs: 10_000,
324
otlpServiceName: "t3-server",
325
+ otlpHeaders: undefined,
326
mode: "web",
327
port: state.port,
328
host: state.host,
apps/server/src/config.ts
+2
@@ -73,6 +73,7 @@ export class ServerConfig extends Context.Service<
73
readonly otlpMetricsUrl: string | undefined;
74
readonly otlpExportIntervalMs: number;
75
readonly otlpServiceName: string;
76
+ readonly otlpHeaders: Readonly<Record<string, string>> | undefined;
77
readonly mode: RuntimeMode;
78
readonly port: number;
79
readonly host: string | undefined;
@@ -197,6 +198,7 @@ const makeTest = Effect.fn("ServerConfig.makeTest")(function* (
198
otlpMetricsUrl: undefined,
199
otlpExportIntervalMs: 10_000,
200
otlpServiceName: "t3-server",
201
+ otlpHeaders: undefined,
202
cwd,
203
baseDir,
204
...derivedPaths,
apps/server/src/environment/ServerEnvironment.test.ts
+1
@@ -54,6 +54,7 @@ const makeServerConfig = Effect.fn(function* (baseDir: string) {
54
otlpMetricsUrl: undefined,
55
otlpExportIntervalMs: 10_000,
56
otlpServiceName: "t3-server",
57
+ otlpHeaders: undefined,
58
cwd: process.cwd(),
59
baseDir,
60
mode: "web",
apps/server/src/http.ts
+2
@@ -319,6 +319,7 @@ export const otlpTracesProxyRouteLayer = HttpRouter.add(
319
const request = yield* HttpServerRequest.HttpServerRequest;
320
const config = yield* ServerConfig.ServerConfig;
321
const otlpTracesUrl = config.otlpTracesUrl;
322
+ const otlpHeaders = config.otlpHeaders;
323
const browserTraceCollector = yield* BrowserTraceCollector.BrowserTraceCollector;
324
const httpClient = yield* HttpClient.HttpClient;
325
const bodyJson = cast<unknown, OtlpTracer.TraceData>(yield* request.json);
@@ -343,6 +344,7 @@ export const otlpTracesProxyRouteLayer = HttpRouter.add(
344
return yield* httpClient
345
.post(otlpTracesUrl, {
346
body: HttpBody.jsonUnsafe(bodyJson),
347
+ headers: otlpHeaders,
348
})
349
.pipe(
350
Effect.flatMap(HttpClientResponse.filterStatusOk),
apps/server/src/observability/Layers/Observability.ts
+2
@@ -49,6 +49,7 @@ export const ObservabilityLive = Layer.unwrap(
49
: yield* OtlpTracer.make({
50
url: config.otlpTracesUrl,
51
exportInterval: `${config.otlpExportIntervalMs} millis`,
52
+ headers: config.otlpHeaders,
53
resource: {
54
serviceName: config.otlpServiceName,
55
attributes: {
@@ -80,6 +81,7 @@ export const ObservabilityLive = Layer.unwrap(
81
: OtlpMetrics.layer({
82
url: config.otlpMetricsUrl,
83
exportInterval: `${config.otlpExportIntervalMs} millis`,
84
+ headers: config.otlpHeaders,
85
resource: {
86
serviceName: config.otlpServiceName,
87
attributes: {
apps/server/src/server.test.ts
+1
@@ -576,6 +576,7 @@ const buildAppUnderTest = (options?: {
576
otlpMetricsUrl: undefined,
577
otlpExportIntervalMs: 10_000,
578
otlpServiceName: "t3-server",
579
+ otlpHeaders: undefined,
580
mode: "desktop",
581
port: 0,
582
host: "127.0.0.1",
docs/operations/observability.md
+2
@@ -528,6 +528,8 @@ OTLP export:
528
- `T3CODE_OTLP_METRICS_URL`: OTLP metric endpoint
529
- `T3CODE_OTLP_EXPORT_INTERVAL_MS`: export interval, default `10000`
530
- `T3CODE_OTLP_SERVICE_NAME`: service name, default `t3-server`
531
+- `T3CODE_OTLP_HEADERS`: extra headers for both exporters, same format as
532
+ `OTEL_EXPORTER_OTLP_HEADERS`: comma-separated `key=value` pairs with percent-encoded values.
533
534
If the OTLP URLs are unset, local tracing still works and metrics stay in-process only.
535
packages/shared/src/observability.test.ts
+39
-1
@@ -1,4 +1,4 @@
1
-import { assert, describe, it } from "@effect/vitest";
1
+import { assert, describe, expect, it } from "@effect/vitest";
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
import * as Arr from "effect/Array";
4
import * as Cause from "effect/Cause";
@@ -21,6 +21,7 @@ import {
21
makeTraceSink,
22
type TraceRecord,
23
type TraceSinkFlushStats,
24
+ OtlpHeadersFromString,
25
truncateTraceAttributes,
26
} from "./observability.ts";
27
@@ -459,3 +460,40 @@ describe("observability", () => {
460
);
461
});
462
});
463
+
464
+describe("OtlpHeadersFromString", () => {
465
+ const decode = Schema.decodeUnknownSync(OtlpHeadersFromString);
466
+
467
+ it.each([
468
+ {
469
+ name: "decodes percent-encoded values",
470
+ input: "authorization=Basic%20abc%3D%3D,x-tenant=t3",
471
+ expected: { authorization: "Basic abc==", "x-tenant": "t3" },
472
+ },
473
+ {
474
+ name: "ignores whitespace around separators",
475
+ input: "authorization=Basic%20abc%3D%3D, x-tenant = t3 ,",
476
+ expected: { authorization: "Basic abc==", "x-tenant": "t3" },
477
+ },
478
+ {
479
+ name: "keeps literal equals signs inside a value",
480
+ input: "authorization=Bearer abc==",
481
+ expected: { authorization: "Bearer abc==" },
482
+ },
483
+ {
484
+ name: "keeps an empty value",
485
+ input: "x-empty=",
486
+ expected: { "x-empty": "" },
487
+ },
488
+ ])("$name", ({ input, expected }) => {
489
+ expect(decode(input)).toEqual(expected);
490
+ });
491
+
492
+ it.each([
493
+ { name: "rejects a pair without a separator", input: "authorization" },
494
+ { name: "rejects a pair without a key", input: "=value" },
495
+ { name: "rejects a malformed percent-encoding", input: "authorization=%E0" },
496
+ ])("$name", ({ input }) => {
497
+ expect(() => decode(input)).toThrow();
498
+ });
499
+});
packages/shared/src/observability.ts
+51
@@ -3,6 +3,9 @@ import * as Effect from "effect/Effect";
3
import type * as Exit from "effect/Exit";
4
import * as ExitRuntime from "effect/Exit";
5
import * as Option from "effect/Option";
6
+import * as Schema from "effect/Schema";
7
+import * as SchemaIssue from "effect/SchemaIssue";
8
+import * as SchemaTransformation from "effect/SchemaTransformation";
9
import * as Tracer from "effect/Tracer";
10
import { OtlpResource, OtlpTracer } from "effect/unstable/observability";
11
@@ -683,3 +686,51 @@ function parseBigInt(input: string): bigint {
686
return 0n;
687
}
688
}
689
+
690
+/**
691
+ * Parses the `OTEL_EXPORTER_OTLP_HEADERS` wire format used by
692
+ * `T3CODE_OTLP_HEADERS`: W3C Baggage `key=value` pairs joined by commas, with
693
+ * percent-encoded values. Each pair splits at its first `=` so an encoded or
694
+ * literal `=` inside a value survives, and whitespace around the separators is
695
+ * ignored.
696
+ */
697
+export const OtlpHeadersFromString = Schema.String.pipe(
698
+ Schema.decodeTo(
699
+ Schema.Record(Schema.String, Schema.String),
700
+ SchemaTransformation.transformOrFail({
701
+ decode: (input) => {
702
+ const headers: Record<string, string> = {};
703
+ for (const pair of input.split(",")) {
704
+ if (pair.trim() === "") {
705
+ continue;
706
+ }
707
+ const separator = pair.indexOf("=");
708
+ const key = separator === -1 ? "" : pair.slice(0, separator).trim();
709
+ if (key === "") {
710
+ return Effect.fail(
711
+ new SchemaIssue.InvalidValue({
712
+ message: `Expected key=value but received ${JSON.stringify(pair.trim())}.`,
713
+ }),
714
+ );
715
+ }
716
+ try {
717
+ headers[key] = decodeURIComponent(pair.slice(separator + 1).trim());
718
+ } catch {
719
+ return Effect.fail(
720
+ new SchemaIssue.InvalidValue({
721
+ message: `Header ${JSON.stringify(key)} has a malformed percent-encoded value.`,
722
+ }),
723
+ );
724
+ }
725
+ }
726
+ return Effect.succeed(headers);
727
+ },
728
+ encode: (headers) =>
729
+ Effect.succeed(
730
+ Object.entries(headers)
731
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
732
+ .join(","),
733
+ ),
734
+ }),
735
+ ),
736
+);