trace

package
v1.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Method    string
	RTT       time.Duration
	ReqBytes  int
	RespBytes int
	Err       error
}

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

func New(verbose bool) *Tracer

New returns a ready Tracer; verbose only affects the human render's totals line (the JSON document always carries full totals).

func (*Tracer) EmitJSON

func (t *Tracer) EmitJSON(w io.Writer) error

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

func (t *Tracer) Record(method string, rtt time.Duration, reqBytes, respBytes int, err error)

Record adds one call to the current section. Notifications (fire-and-forget sends with no round trip) are skipped. Nil-safe.

func (*Tracer) Render

func (t *Tracer) Render(w io.Writer, plain, verbose bool) error

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) SetPhase

func (t *Tracer) SetPhase(name string, d time.Duration)

SetPhase records a run-level phase duration (build, open, op). Nil-safe.

func (*Tracer) StartSection

func (t *Tracer) StartSection(label string)

StartSection begins a labeled connection section — one per Open, so compat's per-version probes each get their own. Nil-safe.

func (*Tracer) Totals

func (t *Tracer) Totals() (wire time.Duration, sent, recv int)

Totals returns the summed round-trip time and per-direction payload bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL