Fastify >= 3.x
Install the latest version using the npm command below:
npm install @inspector-apm/inspector-nodejs --save
You need an Ingestion Key to create an Inspector instance. You can obtain a key creating a new project in your Inspector dashboard.
If you use dotenv
you can configure the Inspector Ingestion Key in your environment file:
INSPECTOR_INGESTION_KEY=[ingestion key]
To monitor your application code execution you need to do just two things:
Initialize Inspector before you require any other modules in your application - i.e. before fastify
, http
, mysql
, etc.
Attach the inspector.fastify()
function to your fastify app.
// Init Inspector before any other moduleconst inspector = require("@inspector-apm/inspector-nodejs")({ingestionKey: "YOUR INGEST KEY HERE",});​​// Init Fastify instanceconst fastify = require('fastify')()​​// Register inspector integrationfastify.register(inspector.fastify());​​// Continue with your code!// ...
Send an HTTP request to your express app to see the first data in your dashboard.
It's mandatory to call the Inspector instance inside your fastify instance to allow automatic tasks identification.
Inspector will decorate the fastify instance with a new property to access Inspector anywhere in your application:
fastify.inspector.addSegment(...);
By default Inspector will report many different tasks based on the application's dependencies, but you are free to "wrap" some parts of your code that you consider relevant to create a more complete picture of what statements are executed during an execution cycle and its performance.