@devries-cameron20 / t3code-1 / commits / 23ce025f58
Fork 0

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

fix(telemetry): honor opt-out for relay tracing (#14413)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Bilal Bayram committed Oct 20, 2026 at 04:35 UTC 23ce025f5834cc78b8b2c796a20779568bb636b7
13 files changed +218 -5
apps/desktop/src/ipc/DesktopIpcHandlers.ts
+2
@@ -41,6 +41,7 @@ import {
41 getAppBranding,
42 getLocalEnvironmentBootstraps,
43 getLocalEnvironmentBearerToken,
44 + getRelayTelemetryEnabled,
45 getSystemLocale,
46 getWindowFullscreenState,
47 openExternal,
@@ -95,6 +96,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
96 yield* ipc.handleSync(takeLegacyLocalStorage);
97 yield* ipc.handle(completeLegacyLocalStorage);
98 yield* ipc.handleSync(getAppBranding);
99 + yield* ipc.handleSync(getRelayTelemetryEnabled);
100 yield* ipc.handleSync(getSystemLocale);
101 yield* ipc.handleSync(getWindowFullscreenState);
102 yield* ipc.handleSync(getLocalEnvironmentBootstraps);
apps/desktop/src/ipc/channels.ts
+1
@@ -30,6 +30,7 @@ export const CLI_COMMAND_GET_STATE_CHANNEL = "desktop:cli-command-get-state";
30 export const CLI_COMMAND_INSTALL_CHANNEL = "desktop:cli-command-install";
31 export const CLI_COMMAND_UNINSTALL_CHANNEL = "desktop:cli-command-uninstall";
32 export const GET_APP_BRANDING_CHANNEL = "desktop:get-app-branding";
33 +export const GET_RELAY_TELEMETRY_ENABLED_CHANNEL = "desktop:get-relay-telemetry-enabled";
34 export const GET_SYSTEM_LOCALE_CHANNEL = "desktop:get-system-locale";
35 export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps";
36 export const GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:get-local-environment-enabled";
apps/desktop/src/ipc/methods/window.test.ts
+20
@@ -27,6 +27,7 @@ import * as ElectronWindow from "../../electron/ElectronWindow.ts";
27 import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
28 import {
29 getLocalEnvironmentBootstraps,
30 + getRelayTelemetryEnabled,
31 getWindowFullscreenState,
32 pasteAsText,
33 pickProjectFavicon,
@@ -198,6 +199,25 @@ describe("getLocalEnvironmentBootstraps", () => {
199 });
200 });
201
202 +describe("getRelayTelemetryEnabled", () => {
203 + it.effect("reads the desktop host opt-out before returning the renderer policy", () =>
204 + Effect.gen(function* () {
205 + assert.isFalse(
206 + yield* getRelayTelemetryEnabled.handler().pipe(
207 + Effect.provideService(HostProcess.Environment, {
208 + T3CODE_TELEMETRY_ENABLED: "false",
209 + }),
210 + ),
211 + );
212 + assert.isTrue(
213 + yield* getRelayTelemetryEnabled
214 + .handler()
215 + .pipe(Effect.provideService(HostProcess.Environment, {})),
216 + );
217 + }),
218 + );
219 +});
220 +
221 describe("getWindowFullscreenState", () => {
222 it.effect("reads the current native window state", () => {
223 const window = { isFullScreen: () => true } as Electron.BrowserWindow;
apps/desktop/src/ipc/methods/window.ts
+9
@@ -16,6 +16,7 @@ import {
16 import { PROJECT_FAVICON_EXTENSIONS } from "@t3tools/shared/projectFavicon";
17 import { resolveEditorCommand } from "@t3tools/shared/editor";
18 import * as HostProcess from "@t3tools/shared/HostProcess";
19 +import { isRelayTracingEnabled } from "@t3tools/shared/otelEnvironment";
20 import * as FileSystem from "effect/FileSystem";
21 import * as Path from "effect/Path";
22 import * as Effect from "effect/Effect";
@@ -71,6 +72,14 @@ export const getAppBranding = DesktopIpc.makeSyncIpcMethod({
72 }),
73 });
74
75 +export const getRelayTelemetryEnabled = DesktopIpc.makeSyncIpcMethod({
76 + channel: IpcChannels.GET_RELAY_TELEMETRY_ENABLED_CHANNEL,
77 + result: Schema.Boolean,
78 + handler: Effect.fn("desktop.ipc.window.getRelayTelemetryEnabled")(function* () {
79 + return isRelayTracingEnabled(yield* HostProcess.Environment);
80 + }),
81 +});
82 +
83 export const getSystemLocale = DesktopIpc.makeSyncIpcMethod({
84 channel: IpcChannels.GET_SYSTEM_LOCALE_CHANNEL,
85 result: Schema.String,
apps/desktop/src/preload.ts
+2
@@ -82,6 +82,8 @@ contextBridge.exposeInMainWorld("desktopBridge", {
82 }
83 return result as ReturnType<DesktopBridge["getAppBranding"]>;
84 },
85 + getRelayTelemetryEnabled: () =>
86 + ipcRenderer.sendSync(IpcChannels.GET_RELAY_TELEMETRY_ENABLED_CHANNEL) === true,
87 getPathForFile: (file: File) => webUtils.getPathForFile(file),
88 getClientPlatform: () => clientPlatform,
89 setNotificationBadge: (badge) =>
apps/server/src/cloud/publicConfig.test.ts
+26
@@ -180,3 +180,29 @@ it("resolves relay client tracing from runtime config with build-time fallback",
180 null,
181 );
182 });
183 +
184 +it("product opt-out disables relay tracing with either built-in or runtime credentials", () => {
185 + const fallback = {
186 + tracesUrl: "https://embedded.example.test/v1/traces",
187 + tracesDataset: "embedded-dataset",
188 + tracesToken: "embedded-token",
189 + };
190 + const env = {
191 + T3CODE_TELEMETRY_ENABLED: "false",
192 + T3CODE_OTEL_SDK_DISABLED: "false",
193 + };
194 +
195 + assert.equal(resolveRelayClientTracingConfig(env, fallback), null);
196 + assert.equal(
197 + resolveRelayClientTracingConfig(
198 + {
199 + ...env,
200 + T3CODE_RELAY_CLIENT_OTLP_TRACES_URL: "https://runtime.example.test/v1/traces",
201 + T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET: "runtime-dataset",
202 + T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN: "runtime-token",
203 + },
204 + fallback,
205 + ),
206 + null,
207 + );
208 +});
apps/server/src/cloud/publicConfig.ts
+5
@@ -4,6 +4,7 @@ import {
4 DEFAULT_HOSTED_APP_URL,
5 } from "@t3tools/shared/connectAuth";
6 import { clerkFrontendApiUrlFromPublishableKey } from "@t3tools/shared/relayAuth";
7 +import { isRelayTracingEnabled } from "@t3tools/shared/otelEnvironment";
8 import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
9 import * as Config from "effect/Config";
10 import * as ConfigProvider from "effect/ConfigProvider";
@@ -85,6 +86,10 @@ export function resolveRelayClientTracingConfig(
86 env: Readonly<Record<string, string | undefined>> = process.env,
87 fallback = buildTimeRelayClientTracing,
88 ) {
89 + if (!isRelayTracingEnabled(env)) {
90 + return null;
91 + }
92 +
93 const tracesUrl = env.T3CODE_RELAY_CLIENT_OTLP_TRACES_URL?.trim() || fallback.tracesUrl;
94 const tracesDataset =
95 env.T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET?.trim() || fallback.tracesDataset;
apps/web/src/cloud/publicConfig.ts
+7
@@ -59,6 +59,13 @@ export function resolveCloudPublicConfig(): CloudPublicConfig {
59 }
60
61 export function resolveRelayTracingConfig() {
62 + // The relay exporter is created during module initialization, so this must be synchronous.
63 + if (
64 + typeof window !== "undefined" &&
65 + window.desktopBridge?.getRelayTelemetryEnabled?.() === false
66 + ) {
67 + return null;
68 + }
69 const { relayTracing } = resolveCloudPublicConfig();
70 return relayTracing.tracesUrl && relayTracing.tracesDataset && relayTracing.tracesToken
71 ? {
apps/web/src/lib/runtime.test.ts
+78 -1
@@ -1,10 +1,16 @@
1 -import { describe, expect, it } from "@effect/vitest";
1 +import { afterEach, describe, expect, it, vi } from "@effect/vitest";
2 +import { withRelayClientTracing } from "@t3tools/shared/relayTracing";
3 import * as Effect from "effect/Effect";
4 import * as Tracer from "effect/Tracer";
5
6 import * as ClientTracer from "../observability/clientTracer";
7 import { runtime } from "./runtime";
8
9 +afterEach(() => {
10 + vi.unstubAllEnvs();
11 + vi.unstubAllGlobals();
12 +});
13 +
14 describe("web runtime", () => {
15 it("routes client spans to the exporter client tracing configured", async () => {
16 const exported: Array<string> = [];
@@ -26,3 +32,74 @@ describe("web runtime", () => {
32 expect(exported).toEqual(["client.work"]);
33 });
34 });
35 +
36 +describe("web runtime relay telemetry policy", () => {
37 + it.each([
38 + {
39 + surface: "desktop opt-out",
40 + desktopBridge: { getRelayTelemetryEnabled: () => false },
41 + exports: false,
42 + },
43 + {
44 + surface: "desktop enabled",
45 + desktopBridge: { getRelayTelemetryEnabled: () => true },
46 + exports: true,
47 + },
48 + { surface: "older desktop bridge", desktopBridge: {}, exports: true },
49 + {
50 + surface: "ordinary browser ignores host opt-out",
51 + desktopBridge: undefined,
52 + exports: true,
53 + },
54 + ])("applies $surface before the first relay span", async ({ desktopBridge, exports }) => {
55 + vi.resetModules();
56 + vi.stubEnv("T3CODE_TELEMETRY_ENABLED", "false");
57 + vi.stubEnv("T3CODE_OTEL_SDK_DISABLED", "true");
58 + vi.stubEnv("OTEL_SDK_DISABLED", "true");
59 + vi.stubEnv("VITE_RELAY_OTLP_TRACES_URL", "https://telemetry.example.test/v1/traces");
60 + vi.stubEnv("VITE_RELAY_OTLP_TRACES_DATASET", "relay-test");
61 + vi.stubEnv("VITE_RELAY_OTLP_TRACES_TOKEN", "test-token");
62 + vi.stubGlobal("window", { desktopBridge });
63 + const fetchFn = vi.fn<typeof fetch>(async () => new Response(null, { status: 202 }));
64 + vi.stubGlobal("fetch", fetchFn);
65 + // Re-import after setting runtime policy: static initialization creates the exporter layer.
66 + const { runtime: freshRuntime } = await import("./runtime");
67 + const { setDelegate } = await import("../observability/clientTracer");
68 + const userSpans: Array<string> = [];
69 +
70 + try {
71 + expect(
72 + await freshRuntime.runPromise(
73 + Effect.succeed("relay operation completed").pipe(
74 + Effect.withSpan("relay.first-operation"),
75 + withRelayClientTracing,
76 + ),
77 + ),
78 + ).toBe("relay operation completed");
79 +
80 + setDelegate(
81 + Tracer.make({
82 + span(options) {
83 + userSpans.push(options.name);
84 + return new Tracer.NativeSpan(options);
85 + },
86 + }),
87 + );
88 + await freshRuntime.runPromise(Effect.void.pipe(Effect.withSpan("user.work")));
89 + expect(userSpans).toEqual(["user.work"]);
90 + } finally {
91 + setDelegate(null);
92 + // Closing the runtime flushes the exporter without waiting for its batch timer.
93 + await freshRuntime.dispose();
94 + }
95 +
96 + if (exports) {
97 + expect(fetchFn).toHaveBeenCalledOnce();
98 + expect(String(fetchFn.mock.calls[0]?.[0])).toBe("https://telemetry.example.test/v1/traces");
99 + const payload = new TextDecoder().decode(fetchFn.mock.calls[0]?.[1]?.body as Uint8Array);
100 + expect(payload).toContain('"name":"relay.first-operation"');
101 + } else {
102 + expect(fetchFn).not.toHaveBeenCalled();
103 + }
104 + });
105 +});
docs/user/telemetry.md
+7 -3
@@ -9,10 +9,14 @@ available.
9 Events do not include prompts, responses, file contents, authentication tokens, conversation IDs,
10 raw provider events, or child-agent output. Child-agent token use is excluded from the totals.
11
12 -To disable collection, set `T3CODE_TELEMETRY_ENABLED=false` in the server's environment before
13 -starting it. This stops product events from being recorded or sent.
12 +T3 Code also sends relay connection traces to Axiom to diagnose T3 Connect connectivity.
13
15 -The desktop app reads the variable from your shell profile (for example `~/.zshrc`) on macOS and
14 +To disable product events and relay tracing, set `T3CODE_TELEMETRY_ENABLED=false` in the server's
15 +environment before starting it. Relay tracing also stops when `T3CODE_OTEL_SDK_DISABLED` or
16 +`OTEL_SDK_DISABLED` turns OpenTelemetry export off. The web app in a browser, including one the
17 +`t3` CLI opens, does not read these variables.
18 +
19 +The desktop app reads `T3CODE_TELEMETRY_ENABLED` from your shell profile (for example `~/.zshrc`) on macOS and
20 Linux, so export it there and restart the app. On Windows, set it as a user environment variable.
21
22 ## Export diagnostics to your own receiver
packages/contracts/src/ipc.ts
+1
@@ -1027,6 +1027,7 @@ export type SystemSettingsPane = typeof SystemSettingsPaneSchema.Type;
1027
1028 export interface DesktopBridge {
1029 getAppBranding: () => DesktopAppBranding | null;
1030 + getRelayTelemetryEnabled?: () => boolean;
1031 getPathForFile?: (file: File) => string;
1032 getClientPlatform?: () => string;
1033 setNotificationBadge?: (badge: { count: number; image: string | null }) => Promise<void>;
packages/shared/src/otelEnvironment.test.ts
+42
@@ -508,3 +508,45 @@ describe("OtelEnvironment", () => {
508 );
509 });
510 });
511 +
512 +describe("isRelayTracingEnabled", () => {
513 + it("defaults on and respects the T3CODE SDK override of the standard kill switch", () => {
514 + assert.isTrue(OtelEnvironment.isRelayTracingEnabled({}));
515 + assert.isFalse(OtelEnvironment.isRelayTracingEnabled({ OTEL_SDK_DISABLED: "true" }));
516 + assert.isTrue(
517 + OtelEnvironment.isRelayTracingEnabled({
518 + OTEL_SDK_DISABLED: "true",
519 + T3CODE_OTEL_SDK_DISABLED: "false",
520 + }),
521 + );
522 + assert.isFalse(
523 + OtelEnvironment.isRelayTracingEnabled({
524 + OTEL_SDK_DISABLED: "false",
525 + T3CODE_OTEL_SDK_DISABLED: "true",
526 + }),
527 + );
528 + });
529 +
530 + it.effect("product opt-out beats SDK enable without disabling user-configured tracing", () =>
531 + Effect.gen(function* () {
532 + const env = {
533 + T3CODE_TELEMETRY_ENABLED: "false",
534 + T3CODE_OTEL_SDK_DISABLED: "false",
535 + OTEL_SDK_DISABLED: "true",
536 + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://user.example.test/v1/traces",
537 + };
538 + assert.isFalse(OtelEnvironment.isRelayTracingEnabled(env));
539 +
540 + const otel = yield* load(env);
541 + assert.isFalse(otel.disabled);
542 + assert.deepStrictEqual(
543 + otel.traces,
544 + OtelEnvironment.OtelSignal.Export({
545 + url: env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
546 + protocol: "http/protobuf",
547 + headers: undefined,
548 + }),
549 + );
550 + }),
551 + );
552 +});
packages/shared/src/otelEnvironment.ts
+18 -1
@@ -246,7 +246,7 @@ const endpointSignal = (name: OtlpSignalName, own: Settings, generic: Settings):
246 };
247 };
248
249 -export const load: Effect.Effect<OtelEnvironment> = Config.all({
249 +const sdkFlags = {
250 t3: flag(
251 "T3CODE_OTEL_SDK_DISABLED",
252 T3CODE_TRUE,
@@ -263,6 +263,10 @@ export const load: Effect.Effect<OtelEnvironment> = Config.all({
263 (value) =>
264 `OTEL_SDK_DISABLED=${value} was read as false; the OpenTelemetry specification recognizes only the string true, so use OTEL_SDK_DISABLED=true or T3CODE_OTEL_SDK_DISABLED to say it any other way`,
265 ),
266 +};
267 +
268 +export const load: Effect.Effect<OtelEnvironment> = Config.all({
269 + ...sdkFlags,
270 resource: resourceAttributes,
271 generic: settings("OTEL_EXPORTER_OTLP_"),
272 traces: settings("OTEL_EXPORTER_OTLP_TRACES_"),
@@ -311,6 +315,19 @@ export const load: Effect.Effect<OtelEnvironment> = Config.all({
315 Effect.orDie,
316 );
317
318 +export const isRelayTracingEnabled = (env: Readonly<Record<string, string | undefined>>) =>
319 + Config.all({
320 + ...sdkFlags,
321 + telemetry: flag("T3CODE_TELEMETRY_ENABLED", T3CODE_TRUE, T3CODE_FALSE, String),
322 + }).pipe(
323 + Effect.map(
324 + ({ telemetry, t3, spec }) => telemetry.value !== false && !(t3.value ?? spec.value ?? false),
325 + ),
326 + Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnvRecord(env))),
327 + Effect.orDie,
328 + Effect.runSync,
329 + );
330 +
331 export type SignalName = "traces" | "metrics" | "logs";
332
333 export interface SignalEndpoint {