Frontend devtools — @djangocfg/devtools
@djangocfg/devtools is the browser counterpart to django_monitor.
One package, one event stream:
- Capture —
window.onerror, unhandled promise rejections,console.warn/console.error, and zod validation events from@djangocfg/apiclients. - Ingest — errors and warnings are batched to
POST /cfg/monitor/ingest/(handled bydjango_monitor) with dedupe, a keepalive flush on page unload, and a circuit breaker that backs off if the endpoint is failing. - Debug panel — a floating button (automatic in development,
?debug=1in production, or ⌘D) opening a filterable log feed plus any app-defined custom tabs.
@djangocfg/devtools replaces the retired @djangocfg/monitor and
@djangocfg/debuger packages — a single dependency in place of the old pair.
Setup
Mount <Devtools> once in your root layout — that is the entire setup:
import { Devtools } from '@djangocfg/devtools'
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Devtools project="my-app" environment={process.env.NODE_ENV} />
</body>
</html>
)
}Capture starts on mount, and ingest posts to /cfg/monitor/ingest/ on the
API origin. The origin must be known: devtools={{ baseUrl }}, or in
BaseApp the auth.apiUrl (derived automatically), or apiUrl for an
auth={false} public app, or NEXT_PUBLIC_API_URL at build time (in turbo it
must be listed in env, an undeclared variable is undefined in the client
bundle). With none of them, ingest is on but nothing can be sent: devtools
logs one console warning naming the fix, and window.devtools.status() shows
baseUrl: ''.
<BaseApp project="site" auth={false} apiUrl={process.env.NEXT_PUBLIC_API_URL}>Precedence: devtools.baseUrl, then apiUrl, then auth.apiUrl, then NEXT_PUBLIC_API_URL.
Imperative API
import { devtools } from '@djangocfg/devtools'
// Goes to both the panel feed AND the backend ingest:
devtools.error('Payment widget crashed', { orderId })
// Component-scoped local logger — panel feed only, never sent to the backend:
const log = devtools.log('CheckoutForm')
log.info('step changed', { step })In the browser console the same API is available as window.devtools
(window.devtools.status(), window.devtools.error('test')).
Check that it reaches Django
window.devtools.status()returns{ ingest, baseUrl, queued, sent, failed, lastError, lastSentAt, circuitOpen }(and prints it):failed > 0withlastErrorsays why,circuitOpenmeans ingest is paused for 60 s after three failed sends.await window.devtools.ping()sends oneinfoevent,devtools ping, now, and resolves withstatus(). django_monitor logs it and never alerts on it.- On the server:
python manage.py monitor_tail --frontendshows it (management commands). Browsererrorandwarningevents and the ping are logged (stdout, andmonitor.login the log directory; loggerdjango_cfg.monitor.frontend), as one flat JSON line. Plaininfo/debug,PAGE_VIEW,PERFORMANCEandCONSOLEevents are not logged unlessMONITOR_LOG_VERBOSEis on. The endpoint takes 64 KB per request, 60 requests and 300 events a minute per client (setMONITOR_CLIENT_IP_HEADERbehind a proxy), and logs a repeating fingerprint once a minute;grep FRONTENDfinds nothing because the event types areJS_ERROR,WARNING, …
Who was signed in
A regular flush (the 5 s timer, a full buffer, ping()) adds Authorization: Bearer <access token> when the visitor is
signed in. The token is read from the key @djangocfg/api writes (cfg.auth.access_token: the shared cookie, else
local or session storage); with none, nothing is added. The request body is unchanged. django_monitor then logs
user_id (the primary key) on the event line; a missing, expired or invalid token only makes the event anonymous.
Details, privacy note and server side: django_monitor, “Which user hit the error”.
Two things to know:
- The flush on page unload (
keepalive,text/plain) is sent without the header.Authorizationis not CORS-safelisted, and adding it would bring back the preflight that the unload flush must avoid, so a crash that closes the tab is reported anonymously. Everything sent while the page lives carries the user. - The API origin must allow the
Authorizationrequest header in CORS. It is in django-cfg’s defaultcors_allow_headers; a project that overrode the list addsauthorization(or setscors_extra_headers). Without it the browser blocks the request on the preflight, and devtools reportsfailedinstatus().
Server-side reporting
For route handlers and React Server Components, the server entry reports errors straight to the ingest endpoint:
import { serverDevtools } from '@djangocfg/devtools/server'
serverDevtools.configure({ project: 'my-app', baseUrl: process.env.API_URL })
await serverDevtools.captureError(err, { url: req.url })TAGS: devtools, frontend, error-tracking, debug-panel, ingest