Import Hud as Early as Possible
Why Early Import Unlocks Full Power
Hud works by mapping and instrumenting your code at runtime.
When you import it early:
- All of your code is tracked, from the very first function call.
- HTTP frameworks like Express, Fastify, and Koa are automatically monitored.
- Queue frameworks like Kafka and SQS are monitored out of the box.
- You get complete call graphs, accurate durations, and contextual error attribution — right from application's startup.
The earlier Hud starts, the more it sees — and the more insight you get.
How to Import Hud the Right Way
Preferred: Preload Hud with --require
--requireThis guarantees Hud is loaded before your app:
node --require ./hud-init.js [YOUR_ENTRY_POINT].jsnpx ts-node --require ./hud-init.ts [YOUR_ENTRY_POINT].tsnest start --exec "node --require ./hud-init.js"// NOTE: Next.js is not fully supported yet, endpoints data will not be collected
// Create a file called instrumentation.ts with the following code:
export async function register() {
require('./hud-init.js');
}//project.json
"my-app": {
"targets": {
"serve": {
"executor": "@nx/js:node",
"options": {
"runtimeArgs": ["--require", "./hud-init.js"],
//...
},
},
}
}// If using `npm run`, check your package.json and modify the relevant script that runs your backend:
"scripts": {
"dev": "node --require ./hud-init.js index.js"
}Or: Import at the Very Top of Your Entry File
Make sure Hud is the first thing imported, before any other module or logic runs.
require('./hud-init.js'); // must come first
// …rest of your appimport './hud-init.ts'; // must come *before* any other imports
// …rest of your appWhat Happens If You Import Too Late?
Hud will still try its best — but it may miss important parts of your system.
Pro Tips
- Always import Hud before any application logic.
- Use register({ verbose: true }) to debug early imports.
- --require is foolproof — we highly recommend it.
- Chat with our support team or email us at [email protected] anytime — we’re happy to help!
Updated about 1 year ago
What’s Next
