Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5a6144a
feat(server,web,desktop): turn telemetry off in Settings or with `t3 …
inayayousfi Oct 29, 2026
f16ff9e
fix(server,web): stop a running flush on opt-out and keep the locked …
inayayousfi Oct 29, 2026
83ba674
fix(server,shared): treat telemetry as off when settings.json cannot …
inayayousfi Oct 29, 2026
4e4cd81
test(server): drive the telemetry CLI test through Effect FileSystem
inayayousfi Oct 29, 2026
bd304f3
fix(desktop): treat an unreadable settings.json as telemetry off
inayayousfi Oct 29, 2026
a19a47e
test(server): the telemetry setting decides after desktop shell disco…
inayayousfi Nov 1, 2026
831e020
fix(server): a late shell telemetry value can only opt out, and Setti…
inayayousfi Nov 1, 2026
ee93a95
fix(server): discard queued usage events as soon as telemetry is turn…
inayayousfi Nov 1, 2026
326fff9
fix(server): an opt-out during a flush stops it even if telemetry is …
inayayousfi Nov 1, 2026
c35354f
fix(web): lock the usage data switch off where a managed policy turns…
inayayousfi Nov 1, 2026
4598ef7
fix(server): a null relay tracing config keeps tracing off
inayayousfi Nov 1, 2026
7ec1504
fix(shared): read the telemetry setting through the narrowed settings…
inayayousfi Nov 3, 2026
9e2100d
fix(web): settings search hides product usage data on servers without…
inayayousfi Nov 3, 2026
e91f7b4
fix(server): t3 telemetry status reports a blank settings file as off
inayayousfi Nov 4, 2026
d55102a
docs: a login shell value can only turn desktop telemetry off
inayayousfi Nov 4, 2026
52f3d38
fix(desktop): a login shell telemetry value can only turn telemetry off
inayayousfi Nov 16, 2026
23f8e0a
fix(server): a T3CODE_TELEMETRY_ENABLED that is not a boolean reads a…
inayayousfi Nov 16, 2026
0c3354b
fix(server): rewriting a blank settings.json keeps telemetry off
inayayousfi Nov 16, 2026
daef1a5
fix(web): move the usage data switch to Maintenance, where the enviro…
inayayousfi Nov 16, 2026
b3e7d36
fix(server): an empty T3CODE_TELEMETRY_ENABLED no longer reads as an …
inayayousfi Nov 16, 2026
1315a17
fix(server): t3 telemetry no longer fails when the variable is not a …
inayayousfi Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/desktop/src/app/DesktopObservability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ const writeObservabilitySettings = Effect.fn(function* (
});

describe("DesktopObservability", () => {
it.effect("reads telemetry as on without a settings file and off when it is unreadable", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-desktop-telemetry-setting-test-",
});
const layerEnvironment = layerEnvironmentFor(baseDir);
const read = DesktopObservability.readPersistedObservabilitySettings.pipe(
Effect.provide(layerEnvironment),
);
assert.isTrue((yield* read).telemetryEnabled);

const { serverSettingsPath } = yield* DesktopEnvironment.DesktopEnvironment.pipe(
Effect.provide(layerEnvironment),
);
// A directory where the file should be fails to read without being missing.
yield* fileSystem.makeDirectory(serverSettingsPath, { recursive: true });
assert.isFalse((yield* read).telemetryEnabled);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect("buffers backend child output and persists it only when a failure is reported", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
24 changes: 13 additions & 11 deletions apps/desktop/src/app/DesktopObservability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as SharedObservability from "@t3tools/shared/observability";
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
import { releaseChannelOf, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
import {
NO_PERSISTED_SERVER_OBSERVABILITY_SETTINGS,
parsePersistedServerObservabilitySettings,
type PersistedServerObservabilitySettings,
} from "@t3tools/shared/serverSettings";
Expand Down Expand Up @@ -330,23 +331,24 @@ export const makeRotatingLogFileWriter = Effect.fn("makeRotatingLogFileWriter")(
} satisfies RotatingLogFileWriter;
});

const noPersistedObservabilitySettings: PersistedServerObservabilitySettings = {
otlpTracesUrl: undefined,
otlpMetricsUrl: undefined,
otlpLogsUrl: undefined,
};

const readPersistedObservabilitySettings: Effect.Effect<
export const readPersistedObservabilitySettings: Effect.Effect<
PersistedServerObservabilitySettings,
never,
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
> = Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const raw = yield* fileSystem.readFileString(environment.serverSettingsPath).pipe(Effect.option);
return Option.isNone(raw)
? noPersistedObservabilitySettings
: parsePersistedServerObservabilitySettings(raw.value);
return yield* fileSystem.readFileString(environment.serverSettingsPath).pipe(
Effect.map(parsePersistedServerObservabilitySettings),
// A missing file saved nothing; an unreadable one may hold a telemetry opt-out.
Effect.catch((cause) =>
Effect.succeed(
cause.reason._tag === "NotFound"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
? NO_PERSISTED_SERVER_OBSERVABILITY_SETTINGS
: { ...NO_PERSISTED_SERVER_OBSERVABILITY_SETTINGS, telemetryEnabled: false },
),
),
);
});

const resolveOtlpEndpoints = Effect.gen(function* () {
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/ipc/DesktopIpcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { startFileDrag } from "./methods/fileDrag.ts";
import * as Effect from "effect/Effect";

import { receiveProviderAuthCallback, cancelProviderAuthCallback } from "./methods/providerAuth.ts";
import * as DesktopObservability from "../app/DesktopObservability.ts";
import * as DesktopIpc from "./DesktopIpc.ts";
import { installNotificationBadge } from "./methods/notificationBadge.ts";
import { getClientSettings, setClientSettings } from "./methods/clientSettings.ts";
Expand Down Expand Up @@ -100,7 +101,9 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
yield* ipc.handleSync(takeLegacyLocalStorage);
yield* ipc.handle(completeLegacyLocalStorage);
yield* ipc.handleSync(getAppBranding);
yield* installRelayTelemetryEnabled();
// The renderer reads this once while loading; a changed setting applies after a restart.
const { telemetryEnabled } = yield* DesktopObservability.readPersistedObservabilitySettings;
yield* installRelayTelemetryEnabled(telemetryEnabled);
yield* ipc.handleSync(getSystemLocale);
yield* ipc.handleSync(getPreferredSystemLanguages);
yield* ipc.handleSync(getPrimaryPasteEnabled);
Expand Down
19 changes: 18 additions & 1 deletion apps/desktop/src/ipc/methods/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ describe("installRelayTelemetryEnabled", () => {
env: NodeJS.ProcessEnv,
policy?: Parameters<typeof DesktopManagedPolicy.layerTest>[0],
loginShellEnv: NodeJS.ProcessEnv = {},
telemetrySetting = true,
) =>
Effect.gen(function* () {
const listeners = new Map<string, DesktopIpc.DesktopIpcSyncListener>();
Expand All @@ -253,7 +254,7 @@ describe("installRelayTelemetryEnabled", () => {
listeners.get(IpcChannels.GET_RELAY_TELEMETRY_ENABLED_CHANNEL)?.(event as never);
return event.returnValue;
};
yield* installRelayTelemetryEnabled().pipe(
yield* installRelayTelemetryEnabled(telemetrySetting).pipe(
Effect.provideService(HostProcess.Environment, env),
Effect.provideService(DesktopShellEnvironment.DesktopShellEnvironment, {
installIntoProcess: Effect.succeed(true),
Expand Down Expand Up @@ -309,6 +310,22 @@ describe("installRelayTelemetryEnabled", () => {
);
}),
);

it.effect("follows the server setting unless the variable was set at launch", () =>
Effect.gen(function* () {
const off = { beforeDiscovery: false, afterDiscovery: false };
assert.deepEqual(yield* relayTelemetryEnabled({}, undefined, {}, false), off);
// A login shell value arrives late and can only opt out.
assert.deepEqual(
yield* relayTelemetryEnabled({}, undefined, { T3CODE_TELEMETRY_ENABLED: "true" }, false),
off,
);
assert.deepEqual(
yield* relayTelemetryEnabled({ T3CODE_TELEMETRY_ENABLED: "true" }, undefined, {}, false),
{ beforeDiscovery: null, afterDiscovery: true },
);
}),
);
});

describe("readMedia", () => {
Expand Down
15 changes: 11 additions & 4 deletions apps/desktop/src/ipc/methods/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,20 @@ export const getAppBranding = DesktopIpc.makeSyncIpcMethod({

/**
* Relay traces leave the machine, so a policy with `telemetry: false`, or one that cannot be read,
* stops them. Read once here: a sync IPC handler cannot wait on the filesystem. Until the login
* shell's environment (which may opt out) is known, answer null so the renderer asks again.
* stops them, and so does the `telemetrySetting` the app started with. Read once: a sync IPC
* handler cannot wait on files. Login shell values arrive later and can only opt out; until
* they are known, answer null so the renderer asks again.
*/
export const installRelayTelemetryEnabled = Effect.fn("desktop.ipc.window.installRelayTelemetry")(
function* () {
function* (telemetrySetting: boolean) {
const ipc = yield* DesktopIpc.DesktopIpc;
const env = yield* HostProcess.Environment;
const policyAllows = yield* (yield* DesktopManagedPolicy.DesktopManagedPolicy).read.pipe(
Effect.map((found) => found?.document.limits?.telemetry !== false),
Effect.orElseSucceed(() => false),
);
// Decided at launch; the login shell's values land in `env` later.
const launchAllows = isRelayTracingEnabled({ ...env }, telemetrySetting);
Comment thread
inayayousfi marked this conversation as resolved.
Resolved
const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
yield* ipc.handleSync(
DesktopIpc.makeSyncIpcMethod({
Expand All @@ -102,7 +105,11 @@ export const installRelayTelemetryEnabled = Effect.fn("desktop.ipc.window.instal
handler: () =>
shellEnvironment.discoveryFinished.pipe(
Effect.map((known) =>
!policyAllows || !isRelayTracingEnabled(env) ? false : known ? true : null,
!policyAllows || !launchAllows || !isRelayTracingEnabled(env)
? false
: known
? true
: null,
),
),
}),
Expand Down
25 changes: 25 additions & 0 deletions apps/desktop/src/shell/DesktopShellEnvironment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,31 @@ describe("DesktopShellEnvironment", () => {
}).pipe(Effect.provide(NodeServices.layer)),
);

it.effect("does not let a login shell value turn telemetry on", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const stateDir = yield* fs.makeTempDirectoryScoped();
yield* fs.writeFileString(
`${stateDir}/shell-environment-cache.json`,
encodeCache({
version: 1,
key: '["darwin","/test-home","/bin/zsh",""]',
environment: { PATH: "/cached/bin", T3CODE_TELEMETRY_ENABLED: "true" },
}),
);
const env: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin" };
yield* runShellEnvironment({
env,
stateDir,
platform: "darwin",
handler: () => "",
use: (service) => service.installIntoProcess,
});
assert.equal(env.PATH, "/cached/bin:/usr/bin");
assert.isUndefined(env.T3CODE_TELEMETRY_ENABLED);
}).pipe(Effect.provide(NodeServices.layer)),
);

it.effect("cancels background discovery when the application scope closes", () =>
Effect.gen(function* () {
const started = yield* Deferred.make<void>();
Expand Down
18 changes: 17 additions & 1 deletion apps/desktop/src/shell/DesktopShellEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setWindowsPath,
windowsEnvironmentValueCommand,
} from "@t3tools/shared/shell";
import { isRelayTracingEnabled } from "@t3tools/shared/otelEnvironment";
import * as Context from "effect/Context";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -656,6 +657,20 @@ const CACHED_ENV_NAMES = [
"T3CODE_TELEMETRY_ENABLED",
] as const;

/**
* A login shell's `T3CODE_TELEMETRY_ENABLED` can only turn telemetry off, so a value that would turn it
* on gives way to what the app was launched with and the `telemetryEnabled` setting decides.
*/
const onlyTelemetryOptOut = (
patch: ShellEnvironmentPatch,
inherited: NodeJS.ProcessEnv,
): ShellEnvironmentPatch => {
const value = patch.T3CODE_TELEMETRY_ENABLED;
if (!value || value === inherited.T3CODE_TELEMETRY_ENABLED) return patch;
if (!isRelayTracingEnabled({ T3CODE_TELEMETRY_ENABLED: value }, false)) return patch;
return { ...patch, T3CODE_TELEMETRY_ENABLED: inherited.T3CODE_TELEMETRY_ENABLED ?? null };
};

/** @public */
export const make = Effect.gen(function* () {
const environment = yield* DesktopEnvironment.DesktopEnvironment;
Expand All @@ -677,9 +692,10 @@ export const make = Effect.gen(function* () {
const discovered = yield* Deferred.make<ShellDiscovery>();
const settledDiscovery = yield* Deferred.make<void>();
const publish = Effect.fn("desktop.shellEnvironment.publish")(function* (
patch: ShellEnvironmentPatch,
shellPatch: ShellEnvironmentPatch,
discovered = false,
) {
const patch = onlyTelemetryOptOut(shellPatch, inherited);
applyShellEnvironment(env, patch, environment.platform);
const message: DesktopShellEnvironmentSnapshot = {
version: 1,
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/binCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
import { sshHelperCommand } from "./cli/sshHelper.ts";
import { serviceCommand } from "./cli/service.ts";
import { servicePreflightCommand } from "./cli/servicePreflight.ts";
import { telemetryCommand } from "./cli/telemetry.ts";
import { themeCommand } from "./cli/theme.ts";
import { traceCommand } from "./cli/trace.ts";
import { triageCommand } from "./cli/triage.ts";
Expand Down Expand Up @@ -109,6 +110,7 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>

servicePreflightCommand,
themeCommand,
telemetryCommand,
traceCommand,
doctorCommand,
policyCommand,
Expand Down
19 changes: 19 additions & 0 deletions apps/server/src/cli/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
otelEnvironment: OtelEnvironment.none,
telemetryEnabledInSettings: true,
devAllowedOrigins: [],
} as const;

Expand Down Expand Up @@ -508,6 +509,24 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
}),
);

it.effect("reads a T3CODE_TELEMETRY_ENABLED that is not a boolean as off", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-config-telemetry-" });
const resolved = yield* resolveServerConfig(minimalDesktopFlags(baseDir), Option.none()).pipe(
Effect.provide(
Layer.mergeAll(
ConfigProvider.layer(
ConfigProvider.fromEnv({ env: { T3CODE_TELEMETRY_ENABLED: "maybe" } }),
),
NetService.layer,
),
),
);
expect(resolved.telemetryEnabledByEnvironment).toBe(false);
}),
);

it.effect("reports the desktop bootstrap as the source of endpoints it supplied", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
17 changes: 15 additions & 2 deletions apps/server/src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
type SignalExport,
} from "@t3tools/shared/observability";
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
import {
NO_PERSISTED_SERVER_OBSERVABILITY_SETTINGS,
parsePersistedServerObservabilitySettings,
} from "@t3tools/shared/serverSettings";
import { DesktopBackendBootstrap, PortSchema } from "@t3tools/contracts";
import * as Config from "effect/Config";
import * as Duration from "effect/Duration";
Expand Down Expand Up @@ -121,6 +124,12 @@ const EnvServerConfig = Config.all({
Config.option,
Config.map(Option.getOrUndefined),
),
// Like the server's live check, a value that is not a boolean turns telemetry off.
telemetryEnabled: Config.Boolean("T3CODE_TELEMETRY_ENABLED").pipe(
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Resolved
Config.option,
Config.map(Option.getOrUndefined),
Config.orElse(() => Config.succeed(false)),
),
otlpExportIntervalMs: Config.Int("T3CODE_OTLP_EXPORT_INTERVAL_MS").pipe(
Config.withDefault(10_000),
),
Expand Down Expand Up @@ -254,7 +263,7 @@ const loadPersistedObservabilitySettings = Effect.fn(function* (settingsPath: st
const fs = yield* FileSystem.FileSystem;
const exists = yield* fs.exists(settingsPath).pipe(Effect.orElseSucceed(() => false));
if (!exists) {
return { otlpTracesUrl: undefined, otlpMetricsUrl: undefined, otlpLogsUrl: undefined };
return NO_PERSISTED_SERVER_OBSERVABILITY_SETTINGS;
}

const raw = yield* fs.readFileString(settingsPath).pipe(Effect.orElseSucceed(() => ""));
Expand Down Expand Up @@ -504,6 +513,10 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
...(logs !== undefined ? { otlpLogsSource: logs.source } : {}),
...(logs?.variable !== undefined ? { otlpLogsVariable: logs.variable } : {}),
otelEnvironment: otel,
...(env.telemetryEnabled === undefined
? {}
: { telemetryEnabledByEnvironment: env.telemetryEnabled }),
telemetryEnabledInSettings: persistedObservabilitySettings.telemetryEnabled,
mode,
port,
cwd,
Expand Down
Loading
Loading