feat(logging): tag logs with a per-session ID - #1073
Open
aqandrew wants to merge 1 commit into
Open
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
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 wrapsthe 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 via
getSessionId()for the later phases.
Because every service already receives
Loggerby injection, session-taggedlogging 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. Thetelemetry
sessionIdfromnewSessionId()is the RFCsession_id(confirmedwith 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.