std/trace
On this page
Index
- type
Span - type
Ring- method
Ring.middleware - method
Ring.record - method
Ring.spans - method
Ring.handler
- method
- fn
ring - fn
id
Types
Span
struct Span {
id: Str
name: Str
start_ms: Int
micros: Int
status: Int
} derive JsonOne timed piece of work of a request: the request’s id, the span’s name
(request for the whole request, a program’s own for the rest), when it
started (Unix milliseconds), how long it took (microseconds), and the
response status for request spans (0 otherwise).
Ring
struct Ring {
buf: Mutex[List[Span]]
cap: Int
}A bounded ring of the last cap spans. Cloning shares it. Its fields
are internal.
Ring.middleware
fn (r: Ring) middleware(rand: Rand, clock: Clock) -> fn(http.Request, http.Next) -> http.Response uses (rand, clock)The request id middleware (router.wrap(ring.middleware(rand, clock))):
takes the id from the X-Request-Id header (when it is 1 to 64
printable characters) or makes a random 64 bit one, puts it in the
request (id(req)), answers it in the X-Request-Id header, and
records a request span.
Ring.record
fn (r: Ring) record(id: Str, name: Str, start: Time, d: Duration)Records a span of the work started at start that took d, for the
request id.
Ring.spans
fn (r: Ring) spans(min: Duration, n: Int) -> List[Span]The spans, newest first, of at most n (all when n <= 0) whose
duration is at least min.
Ring.handler
fn (r: Ring) handler(auth: fn(http.Request) -> Bool) -> fn(http.Request) -> http.ResponseA handler answering the spans as JSON (?slow=MILLIS&n=N; defaults 0
and 100): router.handle("GET /debug/requests", ring.handler(auth));
a request for which auth answers false gets 403.
Functions
ring
fn ring(cap: Int = 1000) -> RingA ring of the last cap spans (default 1000).
id
fn id(req: http.Request) -> StrThe id of a request that passed through the middleware, else “”.
↑ index