@@ -266,6 +266,76 @@ model/provider names, attachment metadata, filenames, tool names, token usage,
266266URLs, error messages, or local chat log text. No chat log category is added to
267267the OpenTelemetry log allowlist.
268268
269+ ## Local MCP server lifecycle
270+
271+ The local MCP HTTP server exports transport lifecycle diagnostics for both
272+ MCP-only mode and gateway-enabled local MCP:
273+
274+ - lifecycle traces: ` openclaw.mcp.server.start ` and
275+ ` openclaw.mcp.server.stop `
276+ - request trace: ` openclaw.mcp.server.request `
277+ - lifecycle counter: ` openclaw.mcp.server.lifecycle.operations `
278+ - request counter: ` openclaw.mcp.server.requests `
279+ - listener-error counter: ` openclaw.mcp.server.listener.errors `
280+ - request-duration histogram: ` openclaw.mcp.server.request.duration `
281+
282+ Lifecycle operations are emitted once per real start or stop attempt. Concurrent
283+ or repeated successful starts do not create duplicate operations. Repeated stop
284+ and disposal calls share the first stop operation. The stop span covers listener
285+ stop and in-flight handler drain. Listener close happens later during resource
286+ disposal, so a close failure increments the listener-error counter but does not
287+ retroactively change the completed stop result.
288+
289+ Request duration is post-accept handling time. It starts after
290+ ` HttpListener.GetContextAsync ` returns, includes handler-limiter admission, body
291+ read, bridge dispatch, and response delivery, and ends at successful delivery or
292+ rejection. It does not include time spent in the HTTP.sys backlog before a
293+ context is accepted.
294+
295+ The MCP request span is an independent transport-level root. A ` tools/call `
296+ request also creates the existing independent ` openclaw.node.tool.invoke ` root,
297+ which measures node dispatch through response delivery. When both spans are
298+ sampled, the node-tool root contains an OpenTelemetry span link to the MCP
299+ request. The link provides structural correlation without changing either
300+ root's parentage or making tool sampling inherit the request's sampling decision,
301+ and without adding a request identifier attribute. A custom link-aware sampler
302+ may still consider links when making its own decision. Gateway tool invocations
303+ and MCP invocations whose request span was not recorded have no link. The overlap
304+ is intentional: the MCP request signal
305+ diagnoses local HTTP transport behavior, while node-tool telemetry diagnoses
306+ command execution. A successfully delivered JSON-RPC error envelope is a
307+ successful MCP transport request; response text is never parsed to classify
308+ telemetry.
309+
310+ Reviewed MCP attributes are:
311+
312+ - ` openclaw.mcp.server.operation ` : ` start ` or ` stop `
313+ - ` openclaw.mcp.server.request.kind ` : ` probe ` , ` json_rpc ` , or ` other `
314+ - ` openclaw.outcome ` : ` success ` , ` failure ` , or ` canceled `
315+ - ` openclaw.error.category ` : ` none ` , ` listener_start ` , ` listener_accept ` ,
316+ ` listener_stop ` , ` listener_close ` , ` authentication_failed ` , ` busy ` , ` timeout ` ,
317+ ` shutdown ` , ` drain_timeout ` , ` invalid_request ` , ` transport_failure ` , or
318+ ` internal_failure `
319+ - ` error.type ` : exception type on spans only
320+
321+ Metrics always include the finite error category, including ` none ` on success,
322+ and never include exception types. Authentication rejection, handler saturation,
323+ invalid HTTP requests, request deadlines, shutdown cancellation, response
324+ delivery failures, and unexpected internal failures are classified through typed
325+ control flow. Deadline and shutdown cancellation use first-wins attribution, so
326+ a later shutdown cannot turn a timeout into cancellation and a later deadline
327+ cannot turn shutdown into timeout. Each source records its cause before
328+ canceling the request token, so request handling cannot observe cancellation
329+ before attribution. If multiple failures occur during stop, the first failure
330+ owns the lifecycle result; later listener failures remain visible through the
331+ listener-error counter.
332+
333+ MCP server telemetry never exports listener ports or endpoints, local or remote
334+ addresses, HTTP scheme or version, headers, user agents, content lengths, bearer
335+ tokens, request or response bodies, JSON-RPC methods or IDs, tool names, command
336+ arguments, or error and exception messages. Existing detailed MCP logs remain
337+ local. No MCP category is added to the OpenTelemetry log allowlist.
338+
269339## Windows node tool calls
270340
271341Gateway ` node.invoke ` and local MCP ` tools/call ` share one node-side telemetry
@@ -288,6 +358,13 @@ do not depend on ambient activity flowing across those boundaries. The
288358invocation tracker uses one monotonic clock for the root and duration metric and
289359completes exactly once.
290360
361+ For local MCP ` tools/call ` , a sampled root links to the sampled
362+ ` openclaw.mcp.server.request ` span that caused it. The link carries only the
363+ standard OpenTelemetry trace and span context. It does not add request IDs,
364+ JSON-RPC fields, tool arguments, or metric tags. The tool invocation remains a
365+ separate root so gateway and MCP command traces retain the same topology and
366+ sampling contract.
367+
291368Reviewed attributes are:
292369
293370- ` openclaw.node.tool.name ` : a registered command or ` unknown `
0 commit comments