NodeJS
Code Execution Monitoring for NodeJS applications.
Last updated
Code Execution Monitoring for NodeJS applications.
Last updated
Install the latest version using the npm command below:
You need an Ingestion Key to create an Inspector instance. Get a new one by creating a project in your dashboard.
If you use dotenv
you can configure the Inspector Ingestion Key in your environment file:
It's important that Inspector is required in the first line of the script, before you require any other modules - i.e. before, http
, mysql
, etc.
This means that you should probably require Inspector in your application's main file (usually index.js
, server.js
or app.js
).
Here's a code example of how Inspector is normally initialized in a NodeJS script:
Inspector wrap incoming http requests in an entity called "Transaction". To create a real picture of what happen in your application during an http request you should start the transaction as soon as possible in the web server.
If the transaction is sterted correctly, Inspector will automatically monitor all other task based on supported modules like mysql2
, pg
, mongodb
, etc.
A NodeJS application that run by the command line can start the transaction immediately after initialization:
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.
Some of the most used modules will be autowired by default. .
Take a look on the example below where a custom web server use to route requests to handlers.
If you are using Express framework, transactions are automatically labeled based on the names of your routes. You should follow the .