Instrumentation
NextFs can also drive the root Next.js instrumentation entry files from F#:
instrumentation.jsinstrumentation-client.js
These are root conventions, like proxy.js, so the generated wrapper files live at the project root rather than under app/**.
Server instrumentation
Use a normal F# module that exports register and, optionally, onRequestError.
module Instrumentation
open NextFs
let register() =
()
let onRequestError(error: InstrumentationError, request: InstrumentationRequest, context: InstrumentationContext) =
ignore error.message
ignore error.digest
ignore request.path
ignore context.routeType
Wrapper entry:
{
"from": "./.fable/Instrumentation.js",
"to": "./instrumentation.js",
"named": ["register", "onRequestError"]
}
Client instrumentation
instrumentation-client.js is a side-effect entry. A thin export * wrapper is enough because importing the compiled Fable module will run its top-level code and re-export any optional named hooks.
module InstrumentationClient
open Fable.Core
open NextFs
[<Emit("performance.mark('nextfs-client-bootstrap')")>]
let private markBootstrap() : unit = jsNative
do markBootstrap()
let onRouterTransitionStart(url: string, navigationType: RouterTransitionType) =
ignore url
ignore navigationType
Wrapper entry:
{
"from": "./.fable/InstrumentationClient.js",
"to": "./instrumentation-client.js",
"exportAll": true
}
Types
Server instrumentation helpers:
InstrumentationErrorInstrumentationRequestInstrumentationContextInstrumentationRouterKindInstrumentationRouteTypeInstrumentationRenderSourceInstrumentationRevalidateReasonInstrumentationRenderType
Client instrumentation helper:
RouterTransitionType
Notes
instrumentation.jsandinstrumentation-client.jsdo not need'use client'or'use server'wrappers.- For multi-argument exports such as
onRequestError, keep the F# signature JavaScript-shaped. instrumentation-client.jsis best modeled as a root module with top-level side effects plus optional named exports.
Related
- root request interception: proxy.js / Proxy
- mixed App Router flows: Server and client patterns
- example layout: Starter example