feat(logging): tag logs with a per-session ID - #1073
Merged
Conversation
Add SessionLogger, which wraps the Coder output channel and prefixes every message with the activation's session ID so all log lines for a session can be correlated by a single ID. Generate the ID once in the ServiceContainer, reuse it as the telemetry session ID, and expose it via getSessionId() for downstream consumers.
This was referenced Aug 11, 2026
aqandrew
force-pushed
the
aqandrew/devex-661-session-logger
branch
from
August 12, 2026 22:00
615ea3b to
445ab75
Compare
EhabY
reviewed
Aug 13, 2026
aqandrew
force-pushed
the
aqandrew/devex-661-session-logger
branch
from
August 13, 2026 18:46
445ab75 to
615ea3b
Compare
…OutputChannel named outputChannel
Replace the SessionLogger class with a prefixLogger(inner, prefix) factory that wraps a Logger and prefixes every message, and rename the module to prefixLogger.ts. The prefix is now generic (a session ID, a workspace name, etc.); the caller passes the bracketed session prefix. Addresses review feedback on #1073.
EhabY
reviewed
Aug 17, 2026
Comment on lines
+51
to
+52
| // One session ID per activation, shared by logs, API requests, | ||
| // telemetry, and the CLI so all data for a session correlates. |
Collaborator
There was a problem hiding this comment.
Nit: this comment will go once we have a the file with a session ID defined at runtime
EhabY
approved these changes
Aug 17, 2026
Prefix logs with [session <shortId>] and render the HTTP request ID as [request <shortId>] so a line clearly identifies both IDs, e.g. '[session ece5f89f] <- [request 38b0a2b4] 200 GET ...'. The full session ID is unchanged on the wire; only the log representation is shortened.
aqandrew
added a commit
that referenced
this pull request
Aug 17, 2026
…v var (#1074) ## What Propagate the session ID from Phase 1 to outbound API requests and to the CLI, so server-side logs, telemetry, and the spawned `coder ssh` process can all be correlated with the extension's session. This is **Phase 2 of 3** for [DEVEX-661](https://linear.app/codercom/issue/DEVEX-661). It builds on #1073. ## Changes - **Requests (RFC req 3):** add a `sessionId` argument to `CoderApi.create` and attach the session ID to every request via the W3C `baggage` header using the `client_session_id` key (`baggage: client_session_id=<hex>`), on both the REST default headers and the WebSocket handshake headers. Threaded through all `CoderApi.create` call sites, including the pre-auth OAuth/login/deployment clients, so every request carries it. - **Telemetry (RFC req 4.2):** already satisfied — the shared ID is the telemetry `sessionId`, which ships on every event's context. - **CLI (RFC reqs 5.2/5.3):** extend `applySshEnvironment` to also set `CODER_TRACE_SESSION_ID` on both `process.env` and the terminal environment collection, so the spawned `coder ssh` ProxyCommand reuses the plugin's session ID instead of generating its own. ## Testing - `pnpm typecheck`, targeted `pnpm lint`, full `pnpm test:extension` (2108 passing). - New tests: `baggage: client_session_id=<hex>` present/absent on `CoderApi`; `CODER_TRACE_SESSION_ID` applied to `process.env` and the terminal collection and restored on dispose. --- 🤖 Generated by Coder Agents.
aqandrew
added a commit
that referenced
this pull request
Aug 21, 2026
## What Add info-level logging of workspace, agent, and lifecycle status transitions so connection debugging has a record of state changes — correlated by the session ID from #1073. This is **Phase 3 of 3** for [DEVEX-661](https://linear.app/codercom/issue/DEVEX-661) (RFC req 7). It builds on #1074. ## Changes State handling is split into three layers, one job each: - **detect** — `WorkspaceStateObserver` / `WorkspaceAgentObserver` (`src/instrumentation/workspace.ts`) each detect a transition once and report a transition object. Stateful but effect-free (no logger/telemetry imports). The agent observer tracks every agent by ID and reports agents that disappear. - **record** — `recordWorkspaceState` / `recordAgentState` emit the `workspace.state_transitioned` / `workspace.agent.state_transitioned` telemetry events. - **log** — inline in `WorkspaceMonitor.update()`, with flat scalar payloads matching the repo's other log sites. Logs `state observed` on first sight, `state changed` afterward, and `agent <name> removed` when an agent disappears. `WorkspaceMonitor` is now the single agent-observation site, so `WorkspaceStateMachine` no longer tracks agent telemetry. > [!IMPORTANT] > **Telemetry data change.** `workspace.agent.state_transitioned` now covers **every agent for the whole monitored session** (deduped per agent), rather than only the connected agent during connection setup. In practice most workspaces have one agent, so volume is unchanged; multi-agent workspaces and flaky connections emit more. There is no sampling in `src/telemetry/`, so this lands as-is. `EVENTS.md` is updated; heads-up to whoever owns the funnel queries. ## Testing - `pnpm typecheck`, targeted `pnpm lint`, full `pnpm test` (2456 passing). - Unit tests cover observer detection (first observation, dedup, per-agent independence, removal, reset), the `record*` event shapes, and the monitor's inline logging (observed vs changed, agent transitions across all agents, agent removal). <details> <summary>Refactor design (reviewer's three-layer shape)</summary> Per the review, the goal was to remove the duplication between the telemetry observers and the state loggers by making transition detection happen once: - **detect**: pure-detection observers report a transition object; no logger or telemetry imports. - **record**: `recordWorkspaceState` / `recordAgentState` in `src/instrumentation/`, telemetry only. - **log**: inline in the monitor, same as every other logging call site. This deletes both `src/workspace/*Logger.ts` files and leaves one tracker per concern. **Observer API decision:** observers return a transition object (workspace → `WorkspaceStateTransition | undefined`; agents → `{ transitions, removed }`) and `WorkspaceMonitor.update()` logs inline and calls `record*`. This was chosen over a constructor callback because `observe()` has a single synchronous caller, so a callback would only hide the side effects and complicate tests. </details> --- 🤖 Generated by Coder Agents.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Introduce a per-session identifier and make the extension tag every log line with it, so all logs for a session can be correlated by searching a single ID.
This is Phase 1 of 3 for DEVEX-661 — "VS Code: add
session_idto all requests, logs, existing telemetry, and CLI invocations".Changes
SessionLogger(src/logging/sessionLogger.ts) — aLoggerthat wraps the Coder output channel and prefixes every message with[<sessionId>].ServiceContainer(reusing the existingnewSessionId()that already backs the telemetry session, so logs, telemetry, requests, and the CLI all share one ID), and expose it viagetSessionId()for the later phases.Because every service already receives
Loggerby injection, session-tagged logging propagates with no call-site changes.Design notes
The code owner (Ehab) suggested composing the session ID and the VS Code logger inside
container.ts'sServiceContainer; this PR follows that approach. The telemetrysessionIdfromnewSessionId()is the RFCsession_id(confirmed with Ehab — reuse it rather than minting a second ID).Testing
pnpm typecheck, targetedpnpm lint, andpnpm test:extension(full suite: 2108 passing).SessionLoggerprefixing and argument forwarding.Implementation plan (DEVEX-661)
Thread a single per-session identifier (16-byte / 32-char lowercase hex) so that
logs, API requests, existing telemetry, and the CLI
sshinvocation theextension drives can all be correlated by one
session_id.In-scope RFC requirements
newSessionId()session_idon every API request via baggagesession_idon VS Code telemetryCODER_TRACE_SESSION_IDviaprocess.env+ terminal env collectioninfo--log-dir+ old-log cleanupOut of scope: coderd tracing middleware (req 6), agent/coordination-protocol
changes and the CLI
sshsubcommand behavior (reqs 8–15) live incoder/coder.Req 13 (in-memory log buffer flushed on connection failure) is deferred to a
follow-up.
Key decisions
sessionIdis the RFCsession_id— one ID,generated once in
ServiceContainer.activation, so container-scoped ≈ per-connection.
[<sessionId>] <message>.baggage: session_id=<hex>header.Phases
SessionLoggercomposition in the container (this PR).CLI via
CODER_TRACE_SESSION_IDonprocess.env+ the terminal envcollection.
info.🤖 Generated by Coder Agents.