Fastify
Code Execution Monitoring for Fastify applications.

Requirements

  • Fastify >= 3.x

Install

Install the latest version using the npm command below:
1
npm install @inspector-apm/inspector-nodejs --save
Copied!

Configure the Ingestion Key

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:
1
INSPECTOR_INGESTION_KEY=[ingestion key]
Copied!

Initialization

Just two steps:
  1. 1.
    Initialize Inspector before you require any other modules in your application - i.e. before fastify, http, mysql, etc.
  2. 2.
    Attach the inspector.fastify() function to your fastify app.
1
// Init Inspector before any other module
2
const inspector = require("@inspector-apm/inspector-nodejs")({
3
ingestionKey: "YOUR INGEST KEY HERE",
4
});
5
6
7
// Init Fastify instance
8
const fastify = require('fastify')()
9
10
11
// Register inspector integration
12
fastify.register(inspector.fastify());
13
14
15
// Continue with your code!
16
// ...
Copied!
Send an HTTP request to your fastify app to see the first data in your dashboard.
Some of the most used modules will be autowired by default. Learn more about autowiring.

Access the Inspector instance

Inspector will decorate the fastify instance with a new property to access Inspector anywhere in your application:
1
fastify.inspector.addSegment(...);
Copied!
It's mandatory to call the Inspector instance inside your fastify instance to allow automatic tasks identification.

Custom Segments

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.
Last modified 2mo ago