Skip to content

Commit 1128272

Browse files
feat: telemetry for the workspace link lifecycle
workspace_linked, workspace_created, workspace_switched, workspace_unlinked on the API success response; workspace_link_failed with a reason class; every failed workspace call reports workspace_api_error or workspace_auth_expired; every envelope carries client. The create-and-link hand-off follows the telemetry module's own decision when the config is unreadable. Closes #1508 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent 346f0f8 commit 1128272

6 files changed

Lines changed: 492 additions & 49 deletions

File tree

‎packages/opencode/src/altimate/plugin/altimate.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import open from "open"
55
import { AltimateApi } from "../api/client"
66
// altimate_change — onboarding telemetry for the gateway sign-in funnel
77
import * as OnboardingTelemetry from "../telemetry/onboarding"
8+
import { Telemetry } from "../telemetry"
89
// altimate_change — shared machine-id helper (race-safe, UUID-validated, size-capped)
910
import { getOrCreateMachineId } from "../util/machine-id"
1011
import { Config } from "@/config/config"
@@ -89,17 +90,21 @@ export async function buildCliContext(machineIdPath?: string): Promise<string> {
8990
} catch (err) {
9091
// Config was unreadable — NOT the normal path. Server routes run inside
9192
// Instance.provide() (AsyncLocalStorage-propagated across awaits), so
92-
// Config.get() resolves during an ordinary browser authorize(). The known
93-
// exception is `altimate auth login <url>`, which deliberately skips
94-
// instance bootstrap (ProvidersLoginCommand `instance: (args) => !isAuthProviderUrl(args.target)`);
95-
// on that path this fires. Fail CLOSED — omit the durable machine_id rather
96-
// than transmit it for a user who may have opted out via config; a missed
97-
// correlation beats leaking a stable identifier. Log so a low correlation
98-
// rate is traceable here instead of being mistaken for a lost reply.
99-
log.warn("cli_context: config unreadable, omitting machine_id (fail-closed)", {
93+
// Config.get() resolves during an ordinary browser authorize(). It fires on
94+
// the paths that skip instance bootstrap: `altimate auth login <url>` and the
95+
// create-and-link hand-off of `altimate-code link`. Follow the telemetry
96+
// module's own decision for this process: it evaluates the same gates in
97+
// doInit() and, with the config unreadable, keeps sending the machine id
98+
// itself — so this context carries the id exactly when telemetry does, and
99+
// omits it whenever telemetry is off (opted out, no sink, test runner).
100+
// Failing closed here instead hid the id from every create-and-link
101+
// hand-off, which made the link step unattributable on the funnel.
102+
await Telemetry.init().catch(() => {})
103+
disabled = !Telemetry.isEnabled()
104+
log.info("cli_context: config unreadable, following telemetry state", {
100105
code: (err as NodeJS.ErrnoException)?.code,
106+
enabled: !disabled,
101107
})
102-
disabled = true
103108
}
104109
}
105110
let machineId = ""

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,64 @@ export namespace Telemetry {
538538
recovered: boolean
539539
duration_ms: number
540540
}
541+
// altimate_change start — workspace link lifecycle (shared event contract: one name per fact,
542+
// the backend's workspace id on every row, fired on the API success response, a `client`
543+
// property stamped on every envelope). The extension emits the same names for its own moments.
544+
| {
545+
type: "workspace_linked"
546+
timestamp: number
547+
session_id: string
548+
workspace_id: number
549+
how: "bind_existing" | "create_and_bind" | "rebind_remote" | "rebind_path"
550+
}
551+
| {
552+
type: "workspace_created"
553+
timestamp: number
554+
session_id: string
555+
workspace_id: number
556+
how: "create_and_bind" | "create_unbound"
557+
}
558+
| {
559+
type: "workspace_link_failed"
560+
timestamp: number
561+
session_id: string
562+
how: "bind_existing" | "create_and_bind" | "create_unbound" | "rebind_remote" | "rebind_path"
563+
reason: "auth" | "not_found" | "network" | "conflict" | "other"
564+
workspace_id?: number
565+
}
566+
| {
567+
type: "workspace_unlinked"
568+
timestamp: number
569+
session_id: string
570+
workspace_id?: number
571+
}
572+
| {
573+
type: "workspace_switched"
574+
timestamp: number
575+
session_id: string
576+
to_workspace_id: number
577+
from_workspace_id?: number
578+
how: "rebind_remote" | "rebind_path"
579+
}
580+
| {
581+
type: "workspace_auth_expired"
582+
timestamp: number
583+
session_id: string
584+
/** Method and path with ids replaced by ":id", e.g. "POST /datamate-project-bindings/bind". */
585+
endpoint: string
586+
status: number
587+
workspace_id?: number
588+
}
589+
| {
590+
type: "workspace_api_error"
591+
timestamp: number
592+
session_id: string
593+
endpoint: string
594+
status_class: "4xx" | "5xx" | "network" | "timeout"
595+
status?: number
596+
workspace_id?: number
597+
}
598+
// altimate_change end
541599
| {
542600
type: "mcp_server_census"
543601
timestamp: number
@@ -1935,6 +1993,9 @@ export namespace Telemetry {
19351993

19361994
const properties: Record<string, string> = {
19371995
cli_version: InstallationVersion,
1996+
// altimate_change — the emitting client, per the shared event contract; `source` below
1997+
// still says how this CLI was launched (cli, tui, serve, datamates).
1998+
client: "altimate-code",
19381999
source: clientSource,
19392000
project_id: fields.project_id ?? projectId,
19402001
...(machineId && { machine_id: machineId }),

0 commit comments

Comments
 (0)