@ogygia/devtools · Profiler
Production
Whether the profiler should ship in a build, and how to run it in one when it does, behind a secret, a login and your own access control. Serverless hosts, source maps and every message it prints are here too.
On this page
A build with the plugin listed runs the same profiler as the dev server, behind a lock. Until you give it a secret of 16 bytes or more, nobody can log in or record. With one, its pages ask for a login, and scripts send the secret in a header.
Recommended setup
The lock has known holes today (#2307), so the recommended default is to leave devtools out of production builds entirely, and to profile a build made for staging or preview instead:
vite build builds in production mode, so that deploy has no profiler and no dock at all. vite build --mode staging builds the same app with them, for a deploy only your team can open.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig(({ mode }) => ({
plugins: [
ogygia(),
...(mode !== 'production'
? [devtools({ profiler: true })]
: []) ,
sveltekit()
]
}));Advanced setup
Keeping the profiler in a production build is the advanced option: it lets you profile the real deploy, on its real hardware and data. Public deploys explains what’s unsafe about it today. If you choose it, this is the whole checklist until #2307 is fixed:
- Set a secret of 16 bytes or more, and keep it out of URLs and logs.
- Put your own access control in front of the whole deploy: a VPN, an IP allow-list, or your host’s password protection.
- Don’t record (page profiles, the trap, sampling, windows) on a deploy the public can reach, and leave
serverTimingoff there. Profile a staging deploy that only your team can open instead. - Give your adapter the real client address (Login), so the key limit is per visitor.
- Give a site sink its own
key, set where the app builds: without one, the profiler’s secret goes to the sink’s host as a bearer token on every post (#2304, item 24). - Keep the dock out with
dock: mode !== 'production', so visitors’ pages carry no launcher.
The request log runs whether anyone logs in or not, invisibly, so the dashboard has history the moment you do.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig(({ mode }) => ({
plugins: [
ogygia(),
devtools({
dock: mode !== 'production',
profiler: true
}),
sveltekit()
]
}));OGYGIA_PROFILER_SECRET=$(openssl rand -hex 32)Secret
The secret comes from the secret option, or from OGYGIA_PROFILER_SECRET, read when the profiler loads on the server’s first request (with onDemand, the first request to /__profiler). It must be at least 16 bytes. What /__profiler answers depends on the secret:
- No secret: a plain-text 404, “ogygia profiler is installed but disabled”. (Its text says
ogygia({ profiler: { secret } }); the option isdevtools({ profiler: { secret } }), #2304.) - A secret under 16 bytes: the server prints
devtools_profiler_secret_shortwhen the profiler loads, nobody can log in, sendx-profiler-keyor profile withx-profile, and/__profileris passed on to your app, which usually answers its own 404 page (#2304). When the profiler seems missing, send the server one request and then check its log. - 16 bytes or more: the login page.
Prefer the environment variable. A secret written in vite.config.ts is baked into the server build, which is what you want only on a host whose running function sees no environment variables (Serverless hosts).
The secret also keys the encrypted .ogp exports and signs sessions and window ids. Changing it ends every session and makes older .ogp files need their old key.
Login
Open /__profiler and log in with the secret. The profiler sets a session cookie, so links inside a report keep working without asking again.
- Sessions are a random id the server signs (HMAC-SHA256 under a key derived from the secret). A session lasts 12 hours. The cookie,
og_profiler, isHttpOnly,SameSite=Lax,Secureon HTTPS, and scoped to the profiler’s path. - Logout (
POST /__profiler/logout) ends the session on the instance that answers it. Another instance accepts it until it expires. Changing the secret ends every session everywhere. - Don’t put the secret in a URL, where a log, a cache or a shared link could keep it. There’s no
?key=parameter: a browser uses the cookie, and a script uses thex-profiler-keyheader. A?key=is ignored, and the redirect to the login copies it into the login page’snext=address, so it ends up in logs anyway. - Wrong keys lock the address out. Wrong keys through the login form,
x-profiler-keyandx-profileshare one budget per client address: after ten in 15 minutes, every key from that address is refused, the right one included, until the window passes. The login form then answers429withretry-after: 900; a request withx-profiler-keyis redirected to the login (a303) as if it had no key; and anx-profilerequest is answered without a profile. A browser that’s already logged in isn’t affected: its session cookie is checked before any key. Every check runs in constant time. - The budget is per client address, as Kit’s
getClientAddress()reports it. Behind a proxy or a CDN, tell your adapter where the real address is (adapter-node’sADDRESS_HEADERandXFF_DEPTH). Otherwise every request carries the proxy’s address, and on a platform with no client address at all every caller shares one budget, so ten wrong keys from anyone lock you out too (#2307). - A second cookie,
og_profiler_beacon, is site-wide and carries no secret. It tells the server to put the visit-reporting script into your documents, so the browser metrics of a report fills in while you use the site. It’s signed for your session and ends with it.
When a browser sends a session cookie the server doesn’t accept, or loops back to the login right after logging in, the server prints devtools_profiler_session_rejected with what the request carried (never a cookie’s value), and the login page says why: no cookie reached the server (a proxy or CDN dropped it), several session cookies, or a secret that differs between instances.
The bare report page (/__profiler/report/<id>) is reachable without a login, so a share link opens for anyone who has its password. The page shows a stored report only to a logged-in visitor; every other route, including the report’s .json, .dump, .html and raw profile, needs the login.
Public deploys
Two known problems (#2307) make the profiler unsafe to record with on a deploy anyone can reach:
- Nested traces leak upstream URLs. With
serverTimingon, any request that sends anx-og-traceheader, with no login, gets back a summary of the request’s outbound calls, full URLs and query strings included:https://api.example.com/reviews?token=…. On the dev server that’s every request. In a build it’s every request made while a page profile runs, and a request profiled withx-profile. - Anyone can lock out your scripts and new logins. Ten wrong
x-profileheaders, which need no login, use up the budget for an address for 15 minutes, and behind an unconfigured proxy that budget is everyone’s. A browser that’s already logged in keeps working, so stay logged in in one browser while you work.
Until #2307 is fixed, a build that keeps the profiler follows the checklist.
The always-on request log and an idle profiler expose nothing: without the secret, every profiler route stays closed. Or leave the profiler out of the build, the recommended default.
The dev server has no lock at all: anyone who can reach it can use the profiler, read your source lines through it, and record. Don’t expose vite dev --host on a network you don’t trust.
Serverless hosts
The live dashboard expects a long-lived Node server: it needs the V8 inspector and memory that lasts between requests. Serverless Node platforms (AWS Lambda, Amplify, Vercel, Netlify) can still record, because the inspector runs in-process, but the report lives on an instance that may be gone before you open it. Edge runtimes such as Workers have no inspector, so nothing beyond the request log runs there.
Three things make a serverless host work:
- Take the report with you. The run page asks for the report back in its own answer and keeps it in your browser, so a report you profiled opens even when its instance is gone. Tick .ogp on the dashboard to download it as a file too.
- Or share a store. With Redis or Postgres every instance writes its reports to the same place (Report storage).
- Load it on demand.
onDemand: truekeeps cold starts from paying for the profiler until someone opens it.
A page profile fits inside the host’s request limit (Limits), and the trap and sampling don’t run there.
Build-time secrets. Some hosts (Amplify, Lambda behind a build step) hand console variables to the build only, and the running function doesn’t see them. For a build that keeps the profiler on such a host (a staging deploy, or the advanced option), pass the secret through the config, and don’t make the profiler option depend on the variable:
For the advanced setup, list devtools({ dock: mode !== 'production', profiler: { … } }) without the mode check instead, as in Advanced setup.
A guard like profiler: env.SECRET && { secret } turns the whole profiler off when the variable is missing at build time, and /__profiler then falls through to your own routing (often an i18n redirect to the home page), which looks like a broken profiler. A configured profiler with an empty secret instead answers /__profiler with a plain “installed but disabled” 404, and the build prints devtools_profiler_secret_empty, so the two cases are easy to tell apart. A secret under 16 bytes behaves like the guard (Secret).
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig(({ mode }) => ({
plugins: [
ogygia(),
...(mode !== 'production'
? [
devtools({
profiler: {
secret:
process.env.OGYGIA_PROFILER_SECRET ,
onDemand: true
}
})
]
: []),
sveltekit()
]
}));Source maps
Production bundles rename and inline code, so without source maps a stack frame points at a chunk file. With the profiler on, the server build writes hidden source maps on its own: .map files beside the server chunks, with no //# sourceMappingURL comment. The profiler reads them to map each frame back to its source file, line and original name. When that worked, the report header says sourcemapped.
- The maps stay on the server. A browser never loads a server chunk. The client build also makes hidden maps, but they never reach a deploy: as soon as the client build has written its output, ogygia moves them into
.svelte-kit/ogygia-client-maps/, a folder no adapter copies. The maps for chunks that hold your own code go into the server module below, and the folder is removed. Nothing in the client output points at a map, and no map is served. - Browser traces get your lines too. A browser CPU trace from a build names minified functions in hashed chunks. The profiler maps them through the kept client maps, so a slow click reads
save (SlowSave.svelte:5). - The maps survive any adapter. An adapter copies what the server code imports, not files read by path: Vercel’s adapter leaves the
.mapfiles behind, and adapter-node re-bundles the chunks with maps that point at files it doesn’t ship. So the build also writes the maps, which source module sits at which chunk line, and yoursrc/source text into one gzipped server module that only the profiler imports, the first time it reads a profile. No request ever loads it. - The cost is disk space. A server output grows from about 6 MB to 12 MB on the playground. The maps module keeps only your own
src/text (not your packages’ text, not imported.json), so 34 MB of maps on a large app ship as 4 MB, and reading a profile unpacks it once into about 11 MB of memory. - Your own setting wins. If you set
build.sourcemapyourself (falseto turn maps off,truefor maps everywhere), ogygia leaves it alone.
Builds without source maps
In a build that turned maps off (build.sourcemap: false), a frame names only its bundled chunk (chunks/frames.js:12). With the profiler on, the build still writes ogygia-modules.json beside the server chunks, recording which source module sits at which lines of each chunk, so the profiler files each frame by what it is: its own code (taken out), ogygia’s runtime and bundled packages, or your app.
A script module’s chunk lines are also matched to its source lines by their text, from the source the build carries. That survives stripped types, dropped comments, a statement wrapped over several lines and two lines folded into one; a line changed beyond matching is placed by its distance from the nearest line that matched. It covers loads, helpers and endpoints, but not components, whose compiled markup isn’t their source: a component’s line keeps the chunk’s number, though its {#each} is still read from the .svelte file.
The slow patterns work on such a build too. A server build isn’t minified, so a chunk’s line reads like your code, and each line says where it came from: src/lib/format.ts (built chunks/format.js:131). On the test pages a build without maps finds every planted slow habit a mapped one does. Only a build made without the profiler on, which carries neither maps nor source, gets a forecast that calls itself partial: a ceiling, and the real time after the fixes will be lower.
Error handling
Everything the profiler prints is a message code, with a page under /e/<code>:
| Code | When |
|---|---|
devtools_profiler_secret_short | The profiler loaded with a secret under 16 bytes. Its pages stay closed. |
devtools_profiler_secret_empty | The build has a secret option that is empty, because the variable it reads wasn’t set where the build ran. |
devtools_profiler_session_rejected | A browser’s session cookie wasn’t accepted, or it looped back right after logging in. |
devtools_profiler_mount_failed | The profiler couldn’t load on the first request (a dev server mid-edit, a broken install). Requests are answered without it, and the next one tries again. A runtime without node:inspector gets devtools_profiler_runtime_unsupported instead, whatever this message’s text says (#2307). |
devtools_profiler_runtime_unsupported | The runtime lacks node:inspector, perf_hooks or process.cpuUsage. Recordings are refused. |
devtools_profiler_background_stopped | A trap or sampling window failed, so that loop stopped. |
devtools_profiler_store_init_failed | The store’s init() threw. Reports stay in memory, and the next use tries the store again (the message’s own text says it falls back until a restart, #2307). |
devtools_profiler_put_report_failed | The store failed to save a report. Printed only with OGYGIA_PROFILER_DEBUG (#2304, item 19). |
devtools_profiler_get_report_failed | The store failed to read a report back, which is then answered as not found. Printed only with OGYGIA_PROFILER_DEBUG. |
devtools_profiler_upload_too_large | An uploaded or posted report unpacked past 256 MB. Answered 413. |
devtools_profiler_sink_undelivered | The sink refused a post after every try. Its rows are dropped. |
devtools_profiler_alloc_sampling_unavailable | The runtime refused allocation sampling, so the recording has no GC attribution. Printed only with OGYGIA_PROFILER_DEBUG. |
devtools_profiler_gc_attribution_failed | Working out who caused the GC threw. Printed only with OGYGIA_PROFILER_DEBUG. |
A store that fails to save a report never breaks the recording: the report stays in this instance’s memory. Without OGYGIA_PROFILER_DEBUG nothing is printed then, so set it while you set up a store.