Installation of the Node.js agent
To use the Node.js monitoring service, the monitoring agent must be installed on the monitored application. For installation, use NPM (Node Package Manager).
-
Install the WhaTap agent module in the active Node.js application directory.
-
Write the configuration of WhaTap agent (whatap.conf).
-
Run the Node.js service again.
Download agent
-
Install the agent in the active Node.js application directory.
$ npm install --save whatap -
Copy the whatap.conf file in the node_modules/whatap path and then paste it into the root path of the project (same location as in the package.json file).
-
Go to the WhaTap Monitoring Service.
-
Select the created project and then copy the following among the downloaded items from the agent in the Install guide section.
Examplelicense={access key}
whatap.server.host={collection server IP} -
Paste it into the whatap.conf file.
The host (whatap.server.host) address is the server address in which the WhaTap proxy has been installed. You can use a forward slash (/) as the delimiter to enter all addresses of the servers where the proxy server is running among the WhaTap servers.
For the agent configuration file, see the following.
Server-side rendering (SSR) frameworks such as Next.js and Nuxt.js require the Custom Server settings for application monitoring. It requires an approach different from typical Node.js frameworks (e.g. Express.js, Nest.js). For more information, see the following:
Using
Set the WHATAP_HOME environment variable
Set the application directory path to the WHATAP_HOME environment variable. If you do not specify it, the current working directory (process.cwd()) is used by default.
export WHATAP_HOME={app_root_path}
Create a whatap.conf file in the WHATAP_HOME path and set the following values.
# whatap.conf
app_name=MyNodeApp # Application name, default: NODE
app_process_name=node # Process name (for example, node)
Configure the agent
Add the following code at the top of the entry point (main module) file of the application. For example, in the Express.js application, app.js and server.js are the entry points (main module). When using a framework like Nest.js, main.ts is the entry point.
- CommonJS
- ECMAScript Module(ESM)
var whatap = require('whatap').NodeAgent;
import WhatapAgent from 'whatap';
WhatapAgent.NodeAgent;
Because the agent executable code needs to be run first after starting node.js, it must be placed before the first import.
Setting agent options by environment
To apply settings tailored to each environment of the application, you can modify the settings in the entry point file of the application instead of the whatap.conf file. Noting the code below, apply the settings tailored to your environment.
process.env.WHATAP_CONF = 'whatap_dev.conf'; // Setting for development environment
var WhatapAgent = require('whatap').NodeAgent;
-
In case different projects are run for each environment
Even for the same application, settings are required for each environment, such as development (dev), test (test), and operation (prod). As in the example above, you can use the
WHATAP_CONFenvironment variables to apply settings that are appropriate for the development environment. This allows you to easily manage different settings for each environment. -
In case you must configure different agent options depending on the environment
For development environment, you can increase the logging level. In production environment, you can configure different options for performance optimization. In this case, modify the agent options in the application's entry point file to suit the environment.
-
In case of running applications in cluster mode for PM2
When you run multiple application instances in cluster mode, the system consolidates them and displays them under a single
app_name(WHATAP_HOME).
Using the agent group unit function
Agent group unit function includes group topology and integrated topology. Replace {group identifier} with agent group name in the following code.
process.env.WHATAP_OKIND = '{group identifier}';
var WhatapAgent = require('whatap').NodeAgent;
// Or write the following in whatap.conf
whatap.okind = {group identifier}
Options that can be configured as environment variables
Because you cannot use the whatap.conf file, set the WhaTap agent options as environment variables in the source file.
process.env.profile_http_header_enabled=false;
process.env.profile_http_parameter_enabled=false;
process.env.profile_basetime=500;
process.env.auto_oname_enabled=false;
process.env.auto_oname_prefix='nodejs';
process.env.mtrace_rate=0;
process.env.mtrace_spec='v1';
process.env.stat_mtrace_enabled=false;
process.env.stat_domain_enabled=false;
For more information about the options that can be set in Node.js, see the following.
Next steps
-
Checking the installation
If you have applied all for project creation and agent installation, check the checklist in [the following] (install-check).
-
Agent setting
It provides various features for monitoring by applying some options to the agent configuration file (whatap.conf). It includes basic configuration, configuration for server connection and data transfer, how to manage the configuration files for multiple application servers, and transaction tracing, and more. For more information, see the following.
-
Starting the monitoring
After all settings are made, restart the application server. The agent starts collecting data. First, check whether the monitoring data has been collected in Application Dashboard. For more information about Application Dashboard, see the following.