Observability
Kaelum provides built-in middleware for common observability needs, making it easier to trace requests across microservices and measure performance metrics without adding external dependencies.
Request ID
Section titled “Request ID”The Request ID middleware automatically attaches a unique X-Request-Id header (using standard UUID v4) to every incoming request and outgoing response.
This is essential for:
- Tracing a single request’s lifecycle across multiple services
- Correlating log entries (by logging
req.id) - Error tracking
const kaelum = require('kaelum');const app = kaelum();
// Enable request IDs for all requestsapp.requestId();
app.get('/', (req, res) => { console.log(`Processing request: ${req.id}`); res.send('Hello World');});If an upstream proxy, load balancer, or API Gateway already provides an X-Request-Id header, Kaelum automatically detects and preserves it, ensuring continuous distributed tracing.
See app.requestId() API Reference for options like custom header names or generators.
Server Timing
Section titled “Server Timing”The Timing middleware injects a Server-Timing header into the response, following the official W3C Server-Timing Specification.
This header records the exact total processing duration of the request in milliseconds and allows browsers’ developer tools (Network tab) to display backend timing metrics natively.
// Enable server timing metricsapp.timing();The header format looks like:
Server-Timing: total;dur=12.34See app.timing() API Reference for configuration options.