Skip to content

Cookbook

Real-world patterns for using TimeRun: use metadata effectively, share results with your stack, time web traffic, and analyze timing data.

You already know the API from the Guide: timer overview, measure a block, measure function calls, metadata, and callbacks. Here we show how to apply it to concrete problems.

  1. Use metadata effectively — Add context (e.g. request id, stage) to every measurement by mutating metadata in on_start.
  2. Share results — Send measurements to logs, files, OpenTelemetry, or Prometheus using on_end.
  3. Time web requests — Wrap HTTP requests with Timer in FastAPI, Flask, or Django.
  4. Analyze results — Collect measurements and compute summaries or confidence intervals with standard tools.