Skip to content

Commit 33118d9

Browse files
authored
Add T3CODE_OTLP_PROTOCOL to allow protobuf protocol (#11224)
1 parent 47ace94 commit 33118d9

19 files changed

Lines changed: 206 additions & 20 deletions

‎apps/desktop/scripts/electron-launcher.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function makeDevelopmentEnvironmentScript(environment) {
117117
["T3CODE_OTLP_TRACES_URL", environment.T3CODE_OTLP_TRACES_URL],
118118
["T3CODE_OTLP_EXPORT_INTERVAL_MS", environment.T3CODE_OTLP_EXPORT_INTERVAL_MS],
119119
["T3CODE_OTLP_HEADERS", environment.T3CODE_OTLP_HEADERS],
120+
["T3CODE_OTLP_PROTOCOL", environment.T3CODE_OTLP_PROTOCOL],
120121
["T3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
121122
].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
122123
return [

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ describe("electron development launcher", () => {
2121
VITE_DEV_SERVER_URL: "http://127.0.0.1:8526",
2222
T3CODE_PORT: "16566",
2323
T3CODE_HOME: "/tmp/t3",
24+
T3CODE_OTLP_PROTOCOL: "http/protobuf",
2425
});
2526

2627
assert.include(
2728
environmentScript,
2829
"if [ -z \"${VITE_DEV_SERVER_URL:-}\" ]; then export VITE_DEV_SERVER_URL='http://127.0.0.1:8526'; fi",
2930
);
31+
assert.include(
32+
environmentScript,
33+
"if [ -z \"${T3CODE_OTLP_PROTOCOL:-}\" ]; then export T3CODE_OTLP_PROTOCOL='http/protobuf'; fi",
34+
);
3035
assert.notInclude(environmentScript, "\nexport VITE_DEV_SERVER_URL=");
3136
});
3237

‎apps/desktop/src/app/DesktopConfig.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OtlpHeadersFromString } from "@t3tools/shared/observability";
1+
import { OtlpHeadersFromString, OtlpProtocol } from "@t3tools/shared/observability";
22
import * as Config from "effect/Config";
33
import * as ConfigProvider from "effect/ConfigProvider";
44
import * as Option from "effect/Option";
@@ -50,6 +50,9 @@ export const DesktopConfig = Config.all({
5050
Config.withDefault(10_000),
5151
),
5252
otlpHeaders: Config.schema(OtlpHeadersFromString, "T3CODE_OTLP_HEADERS").pipe(Config.option),
53+
otlpProtocol: Config.schema(OtlpProtocol, "T3CODE_OTLP_PROTOCOL").pipe(
54+
Config.withDefault("http/json"),
55+
),
5356
appImagePath: trimmedString("APPIMAGE"),
5457
disableAutoUpdate: optionalBoolean("T3CODE_DISABLE_AUTO_UPDATE"),
5558
mockUpdates: optionalBoolean("T3CODE_DESKTOP_MOCK_UPDATES"),

‎apps/desktop/src/app/DesktopEnvironment.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("DesktopEnvironment", () => {
5353
T3CODE_OTLP_TRACES_URL: " http://127.0.0.1:4318/v1/traces ",
5454
T3CODE_OTLP_EXPORT_INTERVAL_MS: "2500",
5555
T3CODE_OTLP_HEADERS: "authorization=Basic%20abc%3D%3D,x-tenant=t3",
56+
T3CODE_OTLP_PROTOCOL: "http/protobuf",
5657
},
5758
);
5859

@@ -93,6 +94,7 @@ describe("DesktopEnvironment", () => {
9394
"x-tenant": "t3",
9495
}),
9596
);
97+
assert.equal(environment.otlpProtocol, "http/protobuf");
9698
}),
9799
);
98100

@@ -110,6 +112,7 @@ describe("DesktopEnvironment", () => {
110112
assert.equal(environment.logDir, "/tmp/t3/userdata/logs");
111113
assert.equal(environment.browserArtifactsDir, "/tmp/t3/userdata/browser-artifacts");
112114
assert.equal(environment.serverSettingsPath, "/tmp/t3/userdata/settings.json");
115+
assert.equal(environment.otlpProtocol, "http/json");
113116
}),
114117
);
115118

‎apps/desktop/src/app/DesktopEnvironment.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as DesktopConfig from "./DesktopConfig.ts";
1616
import { resolveLinuxDesktopEntryName } from "./DesktopEarlyElectronStartup.ts";
1717
import { resolveDesktopBaseDir, resolveDesktopStateDir } from "./DesktopStatePaths.ts";
1818
import { isNightlyDesktopVersion } from "../updates/updateChannels.ts";
19+
import type { OtlpProtocol } from "@t3tools/shared/observability";
1920

2021
export interface MakeDesktopEnvironmentInput {
2122
readonly dirname: string;
@@ -73,6 +74,7 @@ export class DesktopEnvironment extends Context.Service<
7374
readonly otlpTracesUrl: Option.Option<string>;
7475
readonly otlpExportIntervalMs: number;
7576
readonly otlpHeaders: Option.Option<Record<string, string>>;
77+
readonly otlpProtocol: OtlpProtocol;
7678
readonly branding: DesktopAppBranding;
7779
readonly displayName: string;
7880
readonly appUserModelId: string;
@@ -227,6 +229,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
227229
otlpTracesUrl: config.otlpTracesUrl,
228230
otlpExportIntervalMs: config.otlpExportIntervalMs,
229231
otlpHeaders: config.otlpHeaders,
232+
otlpProtocol: config.otlpProtocol,
230233
branding,
231234
displayName,
232235
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>

‎apps/desktop/src/app/DesktopObservability.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { PRIMARY_LOCAL_ENVIRONMENT_ID } from "@t3tools/contracts";
2-
import { makeLocalFileTracer, makeTraceSink } from "@t3tools/shared/observability";
2+
import {
3+
makeLocalFileTracer,
4+
makeTraceSink,
5+
otlpSerializationLayer,
6+
} from "@t3tools/shared/observability";
37
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
48
import * as Context from "effect/Context";
59
import * as DateTime from "effect/DateTime";
@@ -17,7 +21,7 @@ import * as Scope from "effect/Scope";
1721
import * as Semaphore from "effect/Semaphore";
1822
import * as SynchronizedRef from "effect/SynchronizedRef";
1923
import * as Tracer from "effect/Tracer";
20-
import { OtlpExporter, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
24+
import { OtlpExporter, OtlpTracer } from "effect/unstable/observability";
2125

2226
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
2327

@@ -592,7 +596,7 @@ const tracerLayer = Layer.unwrap(
592596
"service.mode": environment.isDevelopment ? "development" : "packaged",
593597
},
594598
},
595-
});
599+
}).pipe(Effect.provide(otlpSerializationLayer(environment.otlpProtocol)));
596600
const tracer = yield* makeLocalFileTracer({
597601
filePath: tracePath,
598602
maxBytes: DESKTOP_LOG_FILE_MAX_BYTES,
@@ -604,7 +608,7 @@ const tracerLayer = Layer.unwrap(
604608

605609
return Layer.succeed(Tracer.Tracer, tracer);
606610
}),
607-
).pipe(Layer.provide(OtlpExporter.layerFlusher), Layer.provideMerge(OtlpSerialization.layerJson));
611+
).pipe(Layer.provide(OtlpExporter.layerFlusher));
608612

609613
export const layer = Layer.mergeAll(
610614
backendOutputLogFactoryLayer,

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,13 @@ describe("DesktopBackendConfiguration", () => {
854854
const previousOpenAiKey = process.env.OPENAI_API_KEY;
855855
const previousAnthropicKey = process.env.ANTHROPIC_API_KEY;
856856
const previousOtlpHeaders = process.env.T3CODE_OTLP_HEADERS;
857+
const previousOtlpProtocol = process.env.T3CODE_OTLP_PROTOCOL;
857858
try {
858859
process.env.WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u";
859860
process.env.OPENAI_API_KEY = "openai-key";
860861
process.env.ANTHROPIC_API_KEY = "anthropic-key";
861862
process.env.T3CODE_OTLP_HEADERS = 'authorization="Bearer%20my-token"';
863+
process.env.T3CODE_OTLP_PROTOCOL = "http/protobuf";
862864

863865
yield* Effect.gen(function* () {
864866
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
@@ -878,13 +880,14 @@ describe("DesktopBackendConfiguration", () => {
878880
assert.equal(config.httpBaseUrl.href, "http://172.27.0.99:5050/");
879881
assert.equal(config.env.OPENAI_API_KEY, "openai-key");
880882
assert.equal(config.env.ANTHROPIC_API_KEY, "anthropic-key");
883+
assert.equal(config.env.T3CODE_OTLP_PROTOCOL, "http/protobuf");
881884
// The existing WSLENV is preserved byte-for-byte (note the empty
882885
// "::" segment survives — WSL ignores it, so we don't normalize
883886
// it away) and ANTHROPIC_API_KEY is appended. OPENAI_API_KEY is
884887
// already declared, so it isn't forwarded twice.
885888
assert.equal(
886889
config.env.WSLENV,
887-
"GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY:T3CODE_OTLP_HEADERS",
890+
"GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY:T3CODE_OTLP_HEADERS:T3CODE_OTLP_PROTOCOL",
888891
);
889892
}).pipe(
890893
Effect.provide(
@@ -908,6 +911,7 @@ describe("DesktopBackendConfiguration", () => {
908911
restoreEnv("OPENAI_API_KEY", previousOpenAiKey);
909912
restoreEnv("ANTHROPIC_API_KEY", previousAnthropicKey);
910913
restoreEnv("T3CODE_OTLP_HEADERS", previousOtlpHeaders);
914+
restoreEnv("T3CODE_OTLP_PROTOCOL", previousOtlpProtocol);
911915
}
912916
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
913917
);

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ const DESKTOP_BACKEND_ENV_NAMES = [
8787
"T3CODE_TAILSCALE_SERVE_PORT",
8888
] as const;
8989

90-
// Sensitive env vars that the WSL backend needs but Windows process.env won't
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
90+
// Env vars that the WSL backend needs but Windows process.env won't forward
91+
// across the wsl.exe boundary without WSLENV. The dev-server URL is handled
92+
// separately via a `--dev-url` CLI flag because WSLENV translation of
9393
// URL-shaped values (colons / slashes) is unreliable.
9494
const WSL_FORWARDED_ENV_NAMES = [
9595
"OPENAI_API_KEY",
9696
"ANTHROPIC_API_KEY",
9797
"T3CODE_OTLP_HEADERS",
98+
"T3CODE_OTLP_PROTOCOL",
9899
] as const;
99100

100101
const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";

‎apps/server/src/bin.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const makeCliTestServerConfig = (baseDir: string) =>
102102
otlpExportIntervalMs: 10_000,
103103
otlpServiceName: "t3-server",
104104
otlpHeaders: undefined,
105+
otlpProtocol: "http/json",
105106
mode: "web",
106107
port: 0,
107108
host: "127.0.0.1",

‎apps/server/src/cli/config.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
5353
otlpExportIntervalMs: 10_000,
5454
otlpServiceName: "t3-server",
5555
otlpHeaders: undefined,
56+
otlpProtocol: "http/json",
5657
devAllowedOrigins: [],
5758
} as const;
5859

@@ -808,4 +809,40 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
808809
expect(resolved.otlpTracesUrl).toBe("http://collector.internal:4318");
809810
}),
810811
);
812+
813+
it.effect("reads the OTLP protocol from env", () =>
814+
Effect.gen(function* () {
815+
const { join } = yield* Path.Path;
816+
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-otlp-protocol-base");
817+
818+
const resolved = yield* resolveServerConfig(
819+
{
820+
mode: Option.some("web"),
821+
port: Option.some(3773),
822+
host: Option.none(),
823+
baseDir: Option.some(baseDir),
824+
cwd: Option.none(),
825+
devUrl: Option.none(),
826+
noBrowser: Option.none(),
827+
bootstrapFd: Option.none(),
828+
autoBootstrapProjectFromCwd: Option.none(),
829+
logWebSocketEvents: Option.none(),
830+
tailscaleServeEnabled: Option.none(),
831+
tailscaleServePort: Option.none(),
832+
},
833+
Option.none(),
834+
).pipe(
835+
Effect.provide(
836+
Layer.mergeAll(
837+
ConfigProvider.layer(
838+
ConfigProvider.fromEnv({ env: { T3CODE_OTLP_PROTOCOL: "http/protobuf" } }),
839+
),
840+
NetService.layer,
841+
),
842+
),
843+
);
844+
845+
expect(resolved.otlpProtocol).toBe("http/protobuf");
846+
}),
847+
);
811848
});

0 commit comments

Comments
 (0)