Skip to Content
FeaturesModulesMonitorFrontend devtools

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/api clients.
  • Ingest — errors and warnings are batched to POST /cfg/monitor/ingest/ (handled by django_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=1 in 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 > 0 with lastError says why, circuitOpen means ingest is paused for 60 s after three failed sends.
  • await window.devtools.ping() sends one info event, devtools ping, now, and resolves with status(). django_monitor logs it and never alerts on it.
  • On the server: python manage.py monitor_tail --frontend shows it (management commands). Browser error and warning events and the ping are logged (stdout, and monitor.log in the log directory; logger django_cfg.monitor.frontend), as one flat JSON line. Plain info/debug, PAGE_VIEW, PERFORMANCE and CONSOLE events are not logged unless MONITOR_LOG_VERBOSE is on. The endpoint takes 64 KB per request, 60 requests and 300 events a minute per client (set MONITOR_CLIENT_IP_HEADER behind a proxy), and logs a repeating fingerprint once a minute; grep FRONTEND finds nothing because the event types are JS_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. Authorization is 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 Authorization request header in CORS. It is in django-cfg’s default cors_allow_headers; a project that overrode the list adds authorization (or sets cors_extra_headers). Without it the browser blocks the request on the preflight, and devtools reports failed in status().

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

Last updated on