When something breaks
Follow a request
Follow one request from the browser to the database, and see where the time went.
Open Traces in the dashboard, or in a terminal:
kiyesi traceskiyesi traces --all --since 1h --search /api/orderskiyesi trace req_2b77f0d3Slow or failed lists requests that took a second or more, or failed with a server error (a status from 500 to 599). Linked to an incident lists the slow or failed ones that happened during a recent incident, on the servers and frontends it involved. All requests lists the rest too. Paste a request ID to find one anywhere in the 7 days kept, or type an address such as /api/orders. In Logs, open any line with a request ID and choose Follow this request.
Each step, and how it is known
Section titled “Each step, and how it is known”| Step | How it is known | What it needs |
|---|---|---|
| Browser | Measured by the browser snippet | The snippet |
| Web server | Measured from its access log, which records the request ID and the time | Caddy: nothing. nginx: two fields, below |
| Backend app | Measured from your app’s own lines that carry the request ID | One line in the app that logs the ID |
| Database | Matched by time against the slow-query log, so it is likely and not certain | The slow-query log turned on |
| Inside the app | Worked out: the time left once the measured steps are taken away | Nothing |
A database line that carries the request ID itself is measured, not matched. A slow query is matched only when it ran during the request, on the same server or another server of the same project and environment.
This is not code-level tracing: Kiyesi does not show which function inside your app was slow.
Your web server
Section titled “Your web server”Caddy needs nothing: its JSON access log records each request’s headers, the answer’s headers and the time. Turn the log on as in See what a server looked like.
nginx: in the http block, add how long the request took and its ID to the end of your log format:
log_format kiyesi '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time $request_id_out';map $http_x_request_id $request_id_out { default $http_x_request_id; "" $request_id;}access_log /var/log/nginx/access.log kiyesi;and in each location that passes requests to your app:
proxy_set_header X-Request-Id $request_id_out;Then reload nginx. This keeps the browser’s ID, makes one when there is none, and passes it to your app.
Your app
Section titled “Your app”Log the X-Request-Id header with each request, as a field such as reqId, requestId, request_id or trace_id in JSON lines, or as request_id=… in plain text. One line at the end of each request, with its answer and time, gives the backend step its time.
// Express, with pino-http: one JSON line per request, with its ID.import { randomUUID } from "node:crypto";import express from "express";import { pinoHttp } from "pino-http";
const app = express();app.use(pinoHttp({ genReqId: (req) => req.headers["x-request-id"] ?? randomUUID() }));app.get("/hello", (_req, res) => res.send("hello"));app.listen(8080);# Flask: the request's ID on one line at the end of each request.import loggingimport timeimport uuid
from flask import Flask, g, request
logging.basicConfig(level=logging.INFO, format="%(message)s")log = logging.getLogger("app")app = Flask(__name__)
@app.before_requestdef start(): g.request_id = request.headers.get("X-Request-Id") or str(uuid.uuid4()) g.started = time.monotonic()
@app.after_requestdef finish(response): ms = round((time.monotonic() - g.started) * 1000) log.info(f"request_id={g.request_id} {request.method} {request.path} {response.status_code} {ms}ms") return response
@app.get("/hello")def hello(): return "hello"// net/http with log/slog: one JSON line per request, with its ID.package main
import ( "crypto/rand" "fmt" "log/slog" "net/http" "os" "time")
func withRequestID(log *slog.Logger, next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { id := r.Header.Get("X-Request-Id") if id == "" { id = rand.Text() } start := time.Now() next.ServeHTTP(w, r) log.Info("request", "request_id", id, "method", r.Method, "path", r.URL.Path, "ms", time.Since(start).Milliseconds()) })}
func main() { log := slog.New(slog.NewJSONHandler(os.Stdout, nil)) mux := http.NewServeMux() mux.HandleFunc("/hello", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "hello") }) if err := http.ListenAndServe(":8080", withRequestID(log, mux)); err != nil { log.Error(err.Error()) }}<?php// At the top of your front controller (public/index.php), whatever the// framework: the request's ID on one line when the request ends.$requestId = $_SERVER['HTTP_X_REQUEST_ID'] ?? bin2hex(random_bytes(16));$started = microtime(true);register_shutdown_function(function () use ($requestId, $started) { error_log(json_encode([ 'request_id' => $requestId, 'method' => $_SERVER['REQUEST_METHOD'], 'path' => parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'status' => http_response_code(), 'ms' => (int) round((microtime(true) - $started) * 1000), ]));});
echo "hello";# A Rack middleware, for Rails, Sinatra or any Rack app: the request's ID on# one line at the end of each request. (In Rails, config.log_tags =# [:request_id] tags every line with it too.)require "logger"require "securerandom"
class RequestId def initialize(app, logger = Logger.new($stdout)) @app = app @logger = logger end
def call(env) id = env["HTTP_X_REQUEST_ID"] || SecureRandom.uuid started = Process.clock_gettime(Process::CLOCK_MONOTONIC) status, headers, body = @app.call(env) ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started) * 1000).round @logger.info("request_id=#{id} #{env['REQUEST_METHOD']} #{env['PATH_INFO']} #{status} #{ms}ms") [status, headers, body] endend
$stdout.sync = trueuse RequestIdrun ->(_env) { [200, { "content-type" => "text/plain" }, ["hello"]] }// The JDK's own server, with a filter: the request's ID on one line at the// end of each request. In Spring Boot, do the same in a OncePerRequestFilter.import com.sun.net.httpserver.Filter;import com.sun.net.httpserver.HttpExchange;import com.sun.net.httpserver.HttpServer;import java.io.IOException;import java.net.InetSocketAddress;import java.util.UUID;import java.util.logging.Logger;
public final class App { static final Logger log = Logger.getLogger("app");
static final class RequestId extends Filter { @Override public void doFilter(HttpExchange ex, Chain chain) throws IOException { String id = ex.getRequestHeaders().getFirst("X-Request-Id"); if (id == null || id.isEmpty()) id = UUID.randomUUID().toString(); long started = System.nanoTime(); chain.doFilter(ex); log.info(String.format("request_id=%s %s %s %d %dms", id, ex.getRequestMethod(), ex.getRequestURI().getPath(), ex.getResponseCode(), (System.nanoTime() - started) / 1_000_000)); }
@Override public String description() { return "logs each request with its X-Request-Id"; } }
public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/hello", ex -> { byte[] body = "hello".getBytes(); ex.sendResponseHeaders(200, body.length); ex.getResponseBody().write(body); ex.close(); }).getFilters().add(new RequestId()); server.start(); }}// ASP.NET Core: a middleware that logs the request's ID on one line at the// end of each request.using System;using System.Diagnostics;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);builder.Logging.ClearProviders();builder.Logging.AddSimpleConsole(o => o.SingleLine = true);var app = builder.Build();var log = app.Logger;
app.Use(async (context, next) =>{ var id = context.Request.Headers["X-Request-Id"].ToString(); if (string.IsNullOrEmpty(id)) id = Guid.NewGuid().ToString(); var watch = Stopwatch.StartNew(); await next(context); log.LogInformation("request_id={RequestId} {Method} {Path} {Status} {Ms}ms", id, context.Request.Method, context.Request.Path, context.Response.StatusCode, watch.ElapsedMilliseconds);});
app.MapGet("/hello", () => "hello");app.Run("http://0.0.0.0:8080");Each of these runs, in its stack’s own official image, for every change: a request with an X-Request-Id goes in, and Kiyesi’s own log reader must find that ID in the app’s line. Fastify needs only genReqId: (req) => req.headers["x-request-id"] ?? randomUUID() with its logger on. In Spring Boot, put the header in a OncePerRequestFilter as the Java tab does, and in Laravel or Symfony the PHP lines go at the top of public/index.php. Without the line’s own time, Kiyesi takes the time from your app’s first line for the request to its last.
Your database
Section titled “Your database”Turn on the slow-query log, and send it where the agent reads it (the database container’s output, or the system log):
- PostgreSQL:
log_min_duration_statement = 200(milliseconds), then reload. - MySQL and MariaDB:
slow_query_log = 1andlong_query_time = 0.2; in a container, alsoslow_query_log_file = /dev/stderr, so the lines reach its output. - MongoDB: on by default for queries over 100 ms; change it with
db.setProfilingLevel(0, { slowms: 200 }).
Kiyesi keeps only the time and the table from these lines, never the query’s values.
Your frontend
Section titled “Your frontend”Add the browser snippet. It adds an ID to your site’s own requests, and for each one that took a second or more, or failed, it sends how long the browser waited. To change that one second, set data-slow-ms, in milliseconds, such as data-slow-ms="500". If your API is on another address, list it in data-trace-origins, after allowing the X-Request-Id header there. If your API already returns an X-Request-Id header that pages may read (Access-Control-Expose-Headers: X-Request-Id), the snippet uses that ID instead and adds nothing.
Where the time went
Section titled “Where the time went”Each trace opens with one sentence, such as 85% of this request was spent inside the backend, outside its database queries. When the web server answered 502 or 504 (it could not reach your app, or your app took too long) and the backend has no line for the request, it says the request stopped at the web server. In the list, the Where the time went column is left out when every request in it spent all its time in one place, as when only the backend’s lines carry the request ID.
Who sees traces
Section titled “Who sees traces”Anyone whose role has View on traces and who can see the servers or frontends involved: Owner, Admin, Member and Viewer, and any role you made with it, only within their projects, and not for servers their role leaves out. Billing and Client do not see traces.
Limits
Section titled “Limits”- Traces are kept 7 days, as log lines are.
- A list shows at most 50 requests; search for an address or ID to narrow it.
If something goes wrong
Section titled “If something goes wrong”- No requests appear. Check that your web server’s log carries the request ID: Caddy’s JSON access log, or nginx’s format above.
- No backend step. Your app’s lines do not carry the ID. See Your app.
- No database step. The slow-query log is off, or no query took long enough to be logged.
- Only the browser saw it. The request reached no server that logs the ID, or the server is not connected.