API performance
Track the latency, errors, and traffic of your own API endpoints. Each request becomes a reserved $api_request event, and the API performance page ranks your slowest (by p95), most error-prone, and busiest endpoints.
Backend (Node/Express) — one line of middleware times every request:
import { TraceIQ } from 'traceiq-node';
const traceiq = new TraceIQ({
projectId: 'YOUR_PROJECT_ID',
writeKey: process.env.TRACEIQ_WRITE_KEY,
endpoint: 'https://api.traceiq.run',
});
// Emits $api_request { method, path, status, durationMs } per request.
app.use(traceiq.middleware({
resolveUserId: (req) => req.user?.id, // optional
ignore: (req) => req.path === '/health', // optional
}));Paths use the matched route template (/users/:id), so requests group cleanly instead of exploding per id.
Backend (Python) — traceiq-py 0.3 times requests the same way for Django, Flask (any WSGI app) and FastAPI (any ASGI app). These are server timings:
# Django: settings.py
from traceiq import Client
TRACEIQ_CLIENT = Client(
project_id="YOUR_PROJECT_ID",
write_key="YOUR_WRITE_KEY",
endpoint="https://api.traceiq.run",
service_name="my-api",
)
TRACEIQ_MIDDLEWARE = { # optional
"resolve_user_id": lambda request: request.user.email if request.user.is_authenticated else None,
"ignore": lambda request: request.path == "/health/",
}
MIDDLEWARE = [
"traceiq.middleware.DjangoMiddleware", # near the top, so it times the middleware below it
# ...
]
# Flask or any WSGI app
from traceiq.middleware import WSGIMiddleware
app.wsgi_app = WSGIMiddleware(app.wsgi_app, traceiq)
# FastAPI, Starlette or any ASGI app
from traceiq.middleware import ASGIMiddleware
app.add_middleware(ASGIMiddleware, client=traceiq)Django and FastAPI report their own route template (/api/pay/verify/:ref/). Flask and other WSGI apps don't expose one, so ids are collapsed (/orders/42 becomes /orders/:id) unless you pass route=. Have resolve_user_id return the same id your frontend passes to identify().
Browser — opt in and the SDK wraps fetch and XMLHttpRequest (so axios and other XHR clients are included) to time each call. Its own calls to TraceIQ are skipped:
traceiq.initialize({
projectId: 'YOUR_PROJECT_ID',
writeKey: 'YOUR_WRITE_KEY',
endpoint: 'https://api.traceiq.run',
autoCaptureRequests: true, // capture outgoing fetch() and XHR as $api_request
// Or narrow it to your backend:
// autoCaptureRequests: { include: ['https://api.example.com'], exclude: [/\/health$/] },
});What browser capture can't see. Only calls made through window.fetch or XMLHttpRequest after initialize() runs are recorded. WebSockets (including Supabase Realtime), navigator.sendBeacon, server actions and server-side fetches never show up. Some clients keep their own copy of fetch from when they were created (older supabase-js releases did), so if such a client is created before TraceIQ initializes, none of its calls are captured. Either initialize TraceIQ first, or hand the client a wrapper that looks up fetch on every call:
export const supabase = createClient(url, anonKey, {
global: { fetch: (...args) => fetch(...args) }
});Only API calls are recorded. Page loads are skipped on both sides: Next.js navigations and prefetches (RSC requests), dev-server/HMR traffic, static assets, and any response that is an HTML page. Pass includePageRequests: true (browser option object, or the middleware option) to record them too.
Server vs browser timings. The middleware measures how long your handler took, which is the number your host (Railway, Render, Fly…) reports. A browser timing is the full round trip from the visitor's device: DNS, TLS, the network distance to your host's region, and the server time. So a 5 ms endpoint can easily show 300–700 ms from a browser on another continent. API performance shows server timings by default whenever your backend sends any; switch to Browser to see what users actually wait for. The Requests explorer has the same filter.
Browser to backend traces. Captured browser calls carry a W3C traceparent header, so when the backend uses traceiq.middleware() its record joins the same trace and nests under the browser request in the Requests waterfall. The header is sent to same-origin requests only: on a cross-origin request it triggers a CORS preflight, which fails unless your API allows the traceparent header. Once it does, list it, e.g. propagateTraceHeaders: ['https://api.example.com'], or pass false to turn propagation off.
Service to service. To follow a request into the services your backend calls, send the same header on outgoing calls. In traceiq-node, set propagateTraceHeaders: ['http://orders.internal'] to add it to fetch() calls made while handling a request, or pass traceiq.traceHeaders() to any other client. Each downstream service that runs the middleware then nests under the request that called it.
WebSocket messages (multiplayer, live updates) aren't HTTP requests, so they never show up here. Record them with traceiq.track() or traceiq.log(); both appear in Logs.
Anything else (gRPC, background jobs) can report directly by sending an $api_request event with method, path, status, and durationMs properties.

