0Pricing
tRPC End-to-End Type Safe APIs · Lesson

Logging and Performance Timing Middleware

Build observability into your tRPC API with middleware that logs every call and measures its execution time.

Why Observe Every Call?

You already use middleware for auth. Middleware is also perfect for cross-cutting concerns like logging and timing that should apply to many procedures.

Middleware Recap

A tRPC middleware wraps a procedure: it runs code, calls next(), then can run code after the result.

const mw = t.middleware(async (opts) => {
  // before
  const result = await opts.next();
  // after
  return result;
});

All lessons in this course

  1. Creating tRPC Context
  2. Authentication Middleware
  3. Custom Middleware Chains
  4. Logging and Performance Timing Middleware
← Back to tRPC End-to-End Type Safe APIs