Skip to content

agentHost: adopt OTEL log channel, support logs from remote agent hosts#317876

Merged
connor4312 merged 1 commit into
mainfrom
connor4312/agenthost-otel-log-channel
May 21, 2026
Merged

agentHost: adopt OTEL log channel, support logs from remote agent hosts#317876
connor4312 merged 1 commit into
mainfrom
connor4312/agenthost-otel-log-channel

Conversation

@connor4312
Copy link
Copy Markdown
Member

Wires up the new channels-otlp/ protocol so the agent host's ILogService is mirrored over an ahp-otlp://logs/{level} channel and surfaced as a per-host Output channel in the workbench.

What changed

Agent host (server)

  • New OtlpLogEmitter / OtlpEmitterLogger in platform/agentHost/common/otlp/. LogService is constructed with the OTLP logger as a secondary sink in both agentHostMain.ts and agentHostServerMain.ts so every log call fans out to subscribers.
  • ProtocolServerHandler advertises telemetry.logs in InitializeResult, routes subscribe/unsubscribe on ahp-otlp: channels through a typed ChannelSubscription discriminated union, canonicalises the channel URI per-level, and broadcasts otlp/exportLogs notifications filtered per subscriber severity.

Workbench (client)

  • RemoteAgentHostProtocolClient captures the full InitializeResult, exposes subscribeStateless, and fires onDidReceiveOtlpLogs for inbound batches.
  • New RemoteAgentHostLogForwarder (in sessions/contrib/providers/remoteAgentHost/browser/) registers a per-host Agent Host (${host}) Output channel via IOutputChannelRegistry, subscribes at the workbench's ILogService level (re-subscribes on change), and appends decoded records. Constructed from remoteAgentHost.contribution.ts::_setupConnection so it covers the WebSocket, SSH and tunnel paths uniformly. Local agent host IPC logging is unchanged.
  • Existing remote IPC traffic channel renamed to Agent Host IPC (${host}) to disambiguate from the new OTLP-derived channel.

Shared utilities

  • UriTemplate moves from workbench/contrib/mcp/common/ to base/common/ so the forwarder can use UriTemplate.parse(template).resolve({ level }) for spec-conformant {level} expansion. MCP imports updated.

Why

The remote agent host already produces structured logs via its ILogService, but until now there was no path for clients to observe them. With this change a remote host's logs (whether spawned over WebSocket, SSH or a dev tunnel) automatically appear in the user's Output panel as Agent Host (${name}), alongside the existing Agent Host IPC (${name}) wire-traffic channel.

Notes for reviewers

  • The local agent host still uses its IPC LoggerChannel (out-of-bounds log forwarding) — only remote connections opt into the OTLP path. This avoids duplicating the existing local Output channel.
  • Output channels are intentionally never deregistered. The set of remote hosts is small and persisting the channel after disconnect lets the user inspect prior log output.
  • _attach short-circuits while not Connected so reconnect cycles don't leak stale subscriptions if the workbench log level changes mid-drop.
  • Server canonicalises the OTLP channel URI on subscribe so URI variants (query/fragment) that parse to the same level collapse to one entry per (client, level).

Tests

  • 8 unit tests for OtlpLogEmitter and helpers (level mappings, payload encode/decode, template expansion).
  • 7 unit tests for the protocol server's OTLP routing (advertise / subscribe / unsubscribe / multi-level / disconnect / unknown URI / URI variant collapse).
  • 3 end-to-end integration tests against a real spawned server (otlpLogs.integrationTest.ts).
  • 25 UriTemplate tests (moved alongside the file).
  • 175 MCP tests still pass after the move; 810 wider AgentHost and 194 RemoteAgentHost tests green.
  • Compile, layer check, and ESLint all clean.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Wires up the new `channels-otlp/` protocol so the agent host's
`ILogService` is mirrored over an `ahp-otlp://logs/{level}` channel
and surfaced as a per-host Output channel in the workbench.

- Add `OtlpLogEmitter` / `OtlpEmitterLogger` (`platform/agentHost/common/otlp/`).
  `LogService` is constructed with the OTLP logger as a secondary sink in both
  `agentHostMain.ts` and `agentHostServerMain.ts` so every log call fans out
  to subscribers.
- `ProtocolServerHandler` advertises `telemetry.logs` in
  `InitializeResult`, routes `subscribe`/`unsubscribe` on `ahp-otlp:`
  channels through a typed `ChannelSubscription` union, canonicalises the
  channel URI per-level, and broadcasts `otlp/exportLogs` notifications
  filtered per subscriber severity.
- `RemoteAgentHostProtocolClient` stores the full `InitializeResult`,
  adds `subscribeStateless` and `onDidReceiveOtlpLogs`.
- New `RemoteAgentHostLogForwarder` in the workbench layer registers an
  `Agent Host (${host})` Output channel via `IOutputChannelRegistry`,
  subscribes at the workbench's `ILogService` level (re-subscribes on
  change), and appends decoded records. Constructed from
  `remoteAgentHost.contribution.ts::_setupConnection` so it covers
  WebSocket, SSH and tunnel paths. Local agent host IPC logging is
  unchanged.
- Existing remote IPC traffic channel renamed to `Agent Host IPC (${host})`
  to disambiguate from the new OTLP-derived channel.
- Move `UriTemplate` from `workbench/contrib/mcp/common/` to
  `base/common/` so the forwarder can use it for `{level}` expansion.

Tests: 8 unit tests for the emitter, 7 for the server-side OTLP routing
(including URI canonicalisation), 3 integration tests for the
end-to-end wire flow, and the existing protocol/handshake/reconnect
suites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 22:44
@connor4312 connor4312 enabled auto-merge (squash) May 21, 2026 22:44
@connor4312 connor4312 merged commit 3400e0f into main May 21, 2026
25 of 26 checks passed
@connor4312 connor4312 deleted the connor4312/agenthost-otel-log-channel branch May 21, 2026 23:04
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 21, 2026
@connor4312 connor4312 review requested due to automatic review settings May 21, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants