Documentation
¶
Overview ¶
Package trace collects round-trip timing for one mcp run: connection phases, every request/response call with approximate payload sizes, and totals. A nil *Tracer is valid and does nothing, so callers gate features on tracer != nil with no second nil-check at each hook. All output goes to writers the caller owns — stdout is never touched (the --json contract keeps stdout as exactly one result document).
Index ¶
- type Call
- type Tracer
- func (t *Tracer) EmitJSON(w io.Writer) error
- func (t *Tracer) Middleware() mcp.Middleware
- func (t *Tracer) Record(method string, rtt time.Duration, reqBytes, respBytes int, err error)
- func (t *Tracer) Render(w io.Writer, plain, verbose bool) error
- func (t *Tracer) SetPhase(name string, d time.Duration)
- func (t *Tracer) StartSection(label string)
- func (t *Tracer) Totals() (wire time.Duration, sent, recv int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
Call is one request/response round trip. RTT covers the full exchange as seen by the sending middleware: SDK marshal + wire + server + decode.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer accumulates one run's timing. It is safe for concurrent use: the SDK permits concurrent in-flight calls, and the middleware records from whatever goroutine the call ran on.
func New ¶
New returns a ready Tracer; verbose only affects the human render's totals line (the JSON document always carries full totals).
func (*Tracer) EmitJSON ¶
EmitJSON writes the structured trace document (phases in ms, sections with per-call rtt_ms/req_bytes/resp_bytes, totals incl. client-internal time).
func (*Tracer) Middleware ¶
func (t *Tracer) Middleware() mcp.Middleware
Middleware returns the client sending middleware that times every request around next() and records it. Register before Connect.
func (*Tracer) Record ¶
Record adds one call to the current section. Notifications (fire-and-forget sends with no round trip) are skipped. Nil-safe.
func (*Tracer) Render ¶
Render writes the human report: one labeled table per section, and under verbose a totals line splitting wire vs client-internal time. Rich mode carries the proportion bar column and ❌ failure markers; plain mode is byte-ASCII with ! failure markers and no bars.
func (*Tracer) StartSection ¶
StartSection begins a labeled connection section — one per Open, so compat's per-version probes each get their own. Nil-safe.