The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 17:00 UTC
fix(observability): every app reports its own environment and release channel (#24340)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Yordis Prieto committed
Oct 25, 2026 at 17:08 UTC
a960f5602fb5eaf8786b619cfcd24a4d441a0473
15 files changed
+129
-15
.github/workflows/web-preview.yml
+2
-1
@@ -82,7 +82,8 @@ jobs:
82
--archive=tgz \
83
--yes \
84
--token "$VERCEL_TOKEN" \
85
- --scope "$vercel_scope"
85
+ --scope "$vercel_scope" \
86
+ --build-env "VITE_RELEASE_CHANNEL=preview"
87
)"
88
printf '%s\n' "$deployment_output"
89
# Vercel can print lockfile warnings to stdout before the deployment URL.
apps/desktop/src/app/DesktopObservability.ts
+10
-2
@@ -7,6 +7,7 @@ import {
7
import * as HostProcess from "@t3tools/shared/HostProcess";
8
import * as SharedObservability from "@t3tools/shared/observability";
9
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
10
+import { releaseChannelOf, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
11
import {
12
parsePersistedServerObservabilitySettings,
13
type PersistedServerObservabilitySettings,
@@ -595,14 +596,21 @@ const layerTelemetry = Layer.unwrap(
596
Effect.gen(function* () {
597
const environment = yield* DesktopEnvironment.DesktopEnvironment;
598
const endpoints = yield* resolveOtlpEndpoints;
599
+ // Unpackaged runs launch a script, so Electron reports its own version.
600
+ const serviceVersion = environment.isPackaged
601
+ ? environment.appVersion
602
+ : desktopPackageJson.version;
603
const resource = {
604
serviceName: "t3code-desktop",
600
- // Unpackaged runs launch a script, so Electron reports its own version.
601
- serviceVersion: environment.isPackaged ? environment.appVersion : desktopPackageJson.version,
605
+ serviceVersion,
606
attributes: {
607
"service.namespace": "t3code",
608
"service.runtime": "desktop",
609
"service.mode": environment.isDevelopment ? "development" : "packaged",
610
+ ...releaseResourceAttributes(
611
+ environment.isDevelopment ? "dev" : releaseChannelOf(serviceVersion),
612
+ endpoints.resourceAttributes,
613
+ ),
614
"host.name": endpoints.resourceAttributes["host.name"] || (yield* HostProcess.Hostname),
615
},
616
};
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+6
-1
@@ -678,7 +678,7 @@ describe("DesktopBackendConfiguration", () => {
678
),
679
);
680
681
- it.effect("resolveWsl carries the kill switch into the distro", () =>
681
+ it.effect("resolveWsl carries the kill switch and resource attributes into the distro", () =>
682
Effect.gen(function* () {
683
const fileSystem = yield* FileSystem.FileSystem;
684
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
@@ -688,10 +688,12 @@ describe("DesktopBackendConfiguration", () => {
688
const previousWslEnv = process.env.WSLENV;
689
const previousDisabled = process.env.OTEL_SDK_DISABLED;
690
const previousTelemetry = process.env.T3CODE_TELEMETRY_ENABLED;
691
+ const previousResourceAttributes = process.env.OTEL_RESOURCE_ATTRIBUTES;
692
try {
693
delete process.env.WSLENV;
694
process.env.OTEL_SDK_DISABLED = "true";
695
process.env.T3CODE_TELEMETRY_ENABLED = "false";
696
+ process.env.OTEL_RESOURCE_ATTRIBUTES = "deployment.environment.name=staging";
697
698
yield* Effect.gen(function* () {
699
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
@@ -701,6 +703,8 @@ describe("DesktopBackendConfiguration", () => {
703
assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
704
assert.equal(config.env.T3CODE_TELEMETRY_ENABLED, "false");
705
assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
706
+ assert.equal(config.env.OTEL_RESOURCE_ATTRIBUTES, "deployment.environment.name=staging");
707
+ assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_RESOURCE_ATTRIBUTES");
708
}).pipe(
709
Effect.provide(
710
layerBackendConfiguration().pipe(
@@ -722,6 +726,7 @@ describe("DesktopBackendConfiguration", () => {
726
restoreEnv("WSLENV", previousWslEnv);
727
restoreEnv("OTEL_SDK_DISABLED", previousDisabled);
728
restoreEnv("T3CODE_TELEMETRY_ENABLED", previousTelemetry);
729
+ restoreEnv("OTEL_RESOURCE_ATTRIBUTES", previousResourceAttributes);
730
}
731
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
732
);
apps/desktop/src/backend/DesktopBackendConfiguration.ts
+1
@@ -110,6 +110,7 @@ const WSL_FORWARDED_ENV_NAMES = [
110
"OTEL_TRACES_EXPORTER",
111
"OTEL_METRICS_EXPORTER",
112
"OTEL_LOGS_EXPORTER",
113
+ "OTEL_RESOURCE_ATTRIBUTES",
114
] as const;
115
116
const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
apps/mobile/src/features/observability/tracing.ts
+12
@@ -1,4 +1,5 @@
1
import Constants from "expo-constants";
2
+import { type ReleaseChannel, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
3
import * as RelayTracing from "@t3tools/shared/relayTracing";
4
5
import { hasTracingPublicConfig, resolveCloudPublicConfig } from "../cloud/publicConfig";
@@ -14,6 +15,12 @@ export interface TracingResource {
15
readonly appVariant: string;
16
}
17
18
+const RELEASE_CHANNEL_BY_VARIANT: Readonly<Record<string, ReleaseChannel | undefined>> = {
19
+ development: "dev",
20
+ preview: "preview",
21
+ production: "stable",
22
+};
23
+
24
export function resolveTracingConfig(): TracingConfig | null {
25
const config = resolveCloudPublicConfig();
26
if (!hasTracingPublicConfig(config)) {
@@ -24,11 +31,16 @@ export function resolveTracingConfig(): TracingConfig | null {
31
}
32
33
export function layerFromConfig(config: TracingConfig | null, resource: TracingResource) {
34
+ const channel =
35
+ typeof __DEV__ !== "undefined" && __DEV__
36
+ ? "dev"
37
+ : RELEASE_CHANNEL_BY_VARIANT[resource.appVariant];
38
return RelayTracing.layer(config, {
39
serviceName: "t3code-mobile",
40
serviceVersion: resource.serviceVersion,
41
runtime: "react-native",
42
client: `mobile-${resource.appVariant}`,
43
+ attributes: channel && releaseResourceAttributes(channel),
44
});
45
}
46
apps/server/src/config.ts
+8
@@ -12,8 +12,15 @@ import type { OtlpEndpointSource } from "@t3tools/contracts";
12
import { sweepStalePendingAttachments } from "./attachmentStore.ts";
13
import { DEFAULT_SIGNAL_EXPORT, type SignalExport } from "@t3tools/shared/observability";
14
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
15
+import { type ReleaseChannel, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
16
import packageJson from "../package.json" with { type: "json" };
17
18
+// Official release workflows set this telemetry channel; other builds report dev.
19
+// Unlike __T3CODE_BUILD_CHANNEL__, this is not the sign-in page's latest/nightly channel.
20
+declare const __T3CODE_TELEMETRY_CHANNEL__: ReleaseChannel | undefined;
21
+export const telemetryChannel: ReleaseChannel =
22
+ typeof __T3CODE_TELEMETRY_CHANNEL__ === "undefined" ? "dev" : __T3CODE_TELEMETRY_CHANNEL__;
23
+
24
export const DEFAULT_PORT = 3773;
25
26
export const RuntimeMode = Schema.Literals(["web", "desktop"]);
@@ -114,6 +121,7 @@ export const otlpResource = (
121
"service.namespace": "t3code",
122
"service.runtime": "t3-server",
123
"t3code.server.managed_by": config.mode === "desktop" ? "desktop" : "standalone",
124
+ ...releaseResourceAttributes(telemetryChannel, config.otelEnvironment.resourceAttributes),
125
"host.name": config.otelEnvironment.resourceAttributes["host.name"] || hostName,
126
},
127
});
apps/server/src/telemetry/AnalyticsService.ts
+1
-7
@@ -50,10 +50,6 @@ const RETRY_MAX_DELAY_MS = 300_000;
50
// These statuses reject the batch itself; unlike 408/429, retrying cannot help.
51
const REJECTED_BATCH_STATUSES = new Set([400, 401, 413]);
52
53
-// Official release workflows set this telemetry channel; other builds report dev.
54
-// Unlike __T3CODE_BUILD_CHANNEL__, this is not the sign-in page's latest/nightly channel.
55
-declare const __T3CODE_TELEMETRY_CHANNEL__: "stable" | "nightly" | "preview" | "dev" | undefined;
56
-
53
/** `random` is in [0, 1). */
54
function retryDelayMs(failures: number, random: number): number {
55
const ceiling = Math.min(RETRY_MAX_DELAY_MS, RETRY_BASE_DELAY_MS * 2 ** (failures - 1));
@@ -142,8 +138,6 @@ export const make = Effect.gen(function* () {
138
// The background flush and the shutdown flush must not send the same batch at once.
139
const flushLock = yield* Semaphore.make(1);
140
const clientType = serverConfig.mode === "desktop" ? "desktop-app" : "cli-web-client";
145
- const telemetryChannel =
146
- typeof __T3CODE_TELEMETRY_CHANNEL__ === "undefined" ? "dev" : __T3CODE_TELEMETRY_CHANNEL__;
141
const hostPlatform = yield* HostProcess.Platform;
142
const hostArchitecture = yield* HostProcess.Architecture;
143
@@ -198,7 +192,7 @@ export const make = Effect.gen(function* () {
192
wsl: Option.getOrUndefined(telemetryConfig.wslDistroName),
193
arch: hostArchitecture,
194
t3CodeVersion: packageJson.version,
201
- telemetryChannel,
195
+ telemetryChannel: ServerConfig.telemetryChannel,
196
clientType,
197
serverOs: serverOsFromNodePlatform(hostPlatform),
198
serverArch: hostArchitecture,
apps/web/src/observability/clientTracing.ts
+9
-1
@@ -8,17 +8,25 @@ import { OtlpExporter, OtlpSerialization, OtlpTracer } from "effect/observabilit
8
import { settleAsyncResult, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
9
import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
10
import { resolvePrimaryEnvironmentHttpUrl } from "../environments/primary";
11
+import { releaseChannelOf, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
12
import * as ClientTracer from "./clientTracer";
13
import * as PrimaryEnvironmentHttpLayer from "../environments/primary/httpLayer";
14
import { isElectron } from "../env";
15
import { APP_VERSION } from "~/branding";
16
17
const DEFAULT_EXPORT_INTERVAL_MS = 1_000;
18
+// PR previews can't mark themselves in APP_VERSION without breaking the version-skew check against the server.
19
+const RELEASE_CHANNEL =
20
+ import.meta.env.DEV || import.meta.env.VITE_RELEASE_CHANNEL === "dev"
21
+ ? "dev"
22
+ : import.meta.env.VITE_RELEASE_CHANNEL === "preview"
23
+ ? "preview"
24
+ : releaseChannelOf(APP_VERSION);
25
const CLIENT_TRACING_RESOURCE = {
26
serviceName: "t3code-web",
27
attributes: {
28
"service.namespace": "t3code",
21
- "deployment.environment.name": import.meta.env.DEV ? "development" : "production",
29
+ ...releaseResourceAttributes(RELEASE_CHANNEL),
30
"service.runtime": "t3-web",
31
"t3code.client.surface": isElectron ? "desktop" : "web",
32
"service.version": APP_VERSION,
apps/web/src/vite-env.d.ts
+1
@@ -7,6 +7,7 @@ interface ImportMetaEnv {
7
readonly VITE_WS_URL: string;
8
readonly VITE_HOSTED_APP_URL: string;
9
readonly VITE_HOSTED_APP_CHANNEL: string;
10
+ readonly VITE_RELEASE_CHANNEL: string;
11
readonly VITE_CLERK_PUBLISHABLE_KEY: string;
12
readonly VITE_CLERK_JWT_TEMPLATE: string;
13
readonly VITE_CLERK_CLI_OAUTH_CLIENT_ID: string;
apps/web/vite.config.ts
+3
@@ -39,6 +39,8 @@ const configuredRelayTracingUrl = repoEnv.VITE_RELAY_OTLP_TRACES_URL?.trim() ||
39
const configuredRelayTracingDataset = repoEnv.VITE_RELAY_OTLP_TRACES_DATASET?.trim() || "";
40
const configuredRelayTracingToken = repoEnv.VITE_RELAY_OTLP_TRACES_TOKEN?.trim() || "";
41
const configuredHostedAppChannel = process.env.VITE_HOSTED_APP_CHANNEL?.trim() || "";
42
+const configuredReleaseChannel =
43
+ process.env.T3CODE_BUILT_DEV === "1" ? "dev" : process.env.VITE_RELEASE_CHANNEL?.trim() || "";
44
const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version;
45
const configuredDesktopUpdateRepository =
46
process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
@@ -237,6 +239,7 @@ export default defineConfig(() => {
239
"import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY": JSON.stringify(
240
configuredDesktopUpdateRepository,
241
),
242
+ "import.meta.env.VITE_RELEASE_CHANNEL": JSON.stringify(configuredReleaseChannel),
243
"import.meta.env.APP_VERSION": JSON.stringify(configuredAppVersion),
244
},
245
resolve: {
docs/operations/observability.md
+11
-3
@@ -627,9 +627,17 @@ with a startup warning, rather than sending it to the Settings endpoint.
627
Service names are fixed: `t3code-server` for the backend and `t3code-desktop` for the desktop main
628
process, both in `service.namespace` `t3code`. `OTEL_SERVICE_NAME` and a `service.name` or
629
`service.namespace` in `OTEL_RESOURCE_ATTRIBUTES` are ignored. Tell installations apart with other
630
-resource attributes, such as `OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=development`.
631
-The UI reports `deployment.environment.name` from its build: `development` under the Vite dev server
632
-and `production` otherwise.
630
+resource attributes, such as `OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=staging`.
631
+
632
+Each process reports its own build, not the one it talks to: the server, the desktop main process,
633
+the UI, and the mobile app each carry `t3code.release.channel` (`dev`, `stable`, `nightly`, or
634
+`preview`, from their own version; desktop PR builds count as `preview`, and a server not built by a
635
+release workflow reports `dev`) and `deployment.environment.name` (`development`, `production`, or
636
+`staging` for `preview`). On the server and the desktop main process either key in
637
+`OTEL_RESOURCE_ATTRIBUTES` wins. The UI and mobile app never read that variable: Vercel PR previews
638
+set `VITE_RELEASE_CHANNEL=preview` because their `APP_VERSION` must stay comparable with the
639
+server's, and the mobile app maps its build variant (`development`, `preview`, `production`), or
640
+reports `dev` from a development bundle.
641
642
Attributes specific to T3 Code use the `t3code.` prefix. The UI runs as `t3code-web` in both a
643
browser and the desktop window, since it is the same code, and `t3code.client.surface` is `desktop`
packages/shared/package.json
+4
@@ -59,6 +59,10 @@
59
"types": "./src/logging.ts",
60
"import": "./src/logging.ts"
61
},
62
+ "./releaseResource": {
63
+ "types": "./src/releaseResource.ts",
64
+ "import": "./src/releaseResource.ts"
65
+ },
66
"./observability": {
67
"types": "./src/observability.ts",
68
"import": "./src/observability.ts"
packages/shared/src/relayTracing.ts
+2
@@ -20,6 +20,7 @@ export interface RelayClientTracingResource {
20
readonly runtime: string;
21
readonly client: string;
22
readonly component?: string;
23
+ readonly attributes?: Readonly<Record<string, string>> | undefined;
24
}
25
26
export class RelayClientTracer extends Context.Reference(
@@ -168,6 +169,7 @@ export function layer(
169
"service.runtime": resource.runtime,
170
"t3code.component": resource.component ?? "relay-client",
171
"t3code.client.surface": resource.client,
172
+ ...resource.attributes,
173
},
174
},
175
}).pipe(Layer.provide(OtlpSerialization.layerJson));
packages/shared/src/releaseResource.test.ts
new
+35
@@ -0,0 +1,35 @@
1
+import { describe, expect, it } from "@effect/vitest";
2
+
3
+import { releaseChannelOf, releaseResourceAttributes } from "./releaseResource.ts";
4
+
5
+describe("releaseResourceAttributes", () => {
6
+ it.each([
7
+ ["dev", {}, "dev", "development"],
8
+ ["stable", {}, "stable", "production"],
9
+ ["nightly", {}, "nightly", "production"],
10
+ ["preview", {}, "preview", "staging"],
11
+ [
12
+ "stable",
13
+ { "deployment.environment.name": "staging", "t3code.release.channel": "" },
14
+ "stable",
15
+ "staging",
16
+ ],
17
+ ] as const)(
18
+ "%s (operator: %o) reports %s in %s",
19
+ (channel, operatorAttributes, expectedChannel, environment) => {
20
+ expect(releaseResourceAttributes(channel, operatorAttributes)).toEqual({
21
+ "t3code.release.channel": expectedChannel,
22
+ "deployment.environment.name": environment,
23
+ });
24
+ },
25
+ );
26
+
27
+ it.each([
28
+ ["0.1.2", "stable"],
29
+ ["0.1.2-nightly.20261025.1", "nightly"],
30
+ ["0.1.2-preview.20261025.1", "preview"],
31
+ ["0.1.2-pr.24340.123", "preview"],
32
+ ] as const)("classifies %s as %s", (version, channel) => {
33
+ expect(releaseChannelOf(version)).toBe(channel);
34
+ });
35
+});
packages/shared/src/releaseResource.ts
new
+24
@@ -0,0 +1,24 @@
1
+import { type CliReleaseChannel, cliReleaseChannelOf } from "./cliRelease.ts";
2
+
3
+export type ReleaseChannel = "dev" | CliReleaseChannel;
4
+
5
+// Desktop PR preview builds are stamped `X.Y.Z-pr.<number>.<run>`; the CLI updater must not see them as preview.
6
+export const releaseChannelOf = (version: string): ReleaseChannel =>
7
+ /-pr\.\d+\.\d+$/.test(version) ? "preview" : cliReleaseChannelOf(version);
8
+
9
+// Effect lets code attributes beat OTEL_RESOURCE_ATTRIBUTES, so the operator value is applied here.
10
+export const releaseResourceAttributes = (
11
+ channel: ReleaseChannel,
12
+ operatorAttributes: Readonly<Record<string, unknown>> = {},
13
+) => {
14
+ const operatorValue = (key: string) => {
15
+ const value = operatorAttributes[key];
16
+ return typeof value === "string" && value !== "" ? value : undefined;
17
+ };
18
+ return {
19
+ "t3code.release.channel": operatorValue("t3code.release.channel") ?? channel,
20
+ "deployment.environment.name":
21
+ operatorValue("deployment.environment.name") ??
22
+ (channel === "dev" ? "development" : channel === "preview" ? "staging" : "production"),
23
+ };
24
+};