Instrumentation
Instrumentation in the Configuration with dusk.config.ts guide.
src/instrumentation.ts is read by the server. Its exports:
register()runs once when the handler is created (the server starts). A failure is reported and the server keeps going.onRequest(request, context)runs before each request is routed.context.routeKindis"unresolved"at that point.onRequestError(error, request, context)sees every error the framework reports, withcontext.phase(request,api,rpc,loader,render,cache,after,instrumentationand others) and the route kind and id.traceris an object with OpenTelemetry'sstartActiveSpanshape. Each request runs inside one span nameddusk.request, with the attributeshttp.request.methodandurl.path, and the loaders, the render, the endpoint that answers (API route, server function, page) and the end of a streamed page get child spans (see Observability). Pass the tracer of@opentelemetry/apior any object with the same methods; Dusk does not depend on OpenTelemetry.
None of these hooks can fail a request: a hook that throws is logged and the request is answered.
src/instrumentation.tsts
export function register(): void {
console.info("dusk server started");
}
export function onRequestError(error: unknown, request: Request | undefined, context: { readonly phase: string; readonly routeKind: string | undefined }): void {
console.error("request failed", context.phase, context.routeKind, request?.url, error);
}