Node.js agent
Use SixthSense Node monitoring to track the exact error in the code. You will get the whole picture of your application environment which will help you in resolving issues.
Prerequisites
- For prerequisite checks for agent installation, see Prerequisite checks for agent installation.
- SixthSense Agent - Node Package See, Downloading the agent.
- URL/IP of the SixthSense collector (the tenant URL which will be provided by the SixthSense Customer Support.)
- Access token - For accessing the token, see Accessing your Access Token under Getting started with the Observability Portal.
- PACKAGE_TOKEN - token from SixthSense Customer Support to download the SixthSense package.
Downloading the agent
- Download the SixthSense agent into your project dependencies."@SixthSense/SixthSense-node-js": "^2.2.5"
- Agent configurations will be added to the entry point of your application. For example, in any Node.js application entry point will be defined in the package.json file and in the following example server.js file is the entry point. Following is the package.json file.
- Add the agent with your dependencies.
Initialise and name the agent
- Entry point to the application is "server.js". For your application the entry point can be different. Hence, add our agent configurations in the entry point file as mentioned below.
- Name the service using the serviceName variable.
For OneCloud Platform use the following command:
- Get Access Token from the SixthSense portal. For accessing the token, see Accessing your Access Token under Getting started with the Observability Portal.
- Add the access token to the entry point file authorization:'Access token'.
For example, see the above snippet.
Run your application
- Run the following commands before the npm install command
To download the agent, download Packages from Gitlab Package Registry.
- PACKAGE_TOKen - provided by SixthSense Customer Support.
- Run npm install command to download all the dependencies.
- Run the start command to run your Node application.
Incase of network restriction to sixthsense backend, you can either use proxy or ask your network team to whitelist the SixthSense backend address to allow connectivity to send data.
- Set proxy at system/container level.
Example: a. Windows Servers: Add environment variable in system level variables for http_proxy, https_proxy b. Linux Servers: Add proxy in the ~/.bashrc file as follows. export http_proxy= 10.0.0.1:3128
- Pass Proxy at node level.
npm config set proxy http://username:password@host:port npm config set https-proxy https://username:password@host:port
- For setting proxy and other configurations for npm, type the following command in the console
npm config edit
This command will open the .npmrc file. Set the proxy, https-proxy related to npm in the file.
note
The various ignore options like SW_IGNORE_SUFFIX, SW_TRACE_IGNORE_PATH and SW_HTTP_IGNORE_METHOD as well as endpoints which are not recorded due to exceeding SW_AGENT_MAX_BUFFER_SIZE all propagate their ignored status downstream to any other endpoints they may call. If that endpoint is running the Node Sixthsense agent then regardless of its ignore settings, it will not be recorded since its upstream parent was not recorded. This allows elimination of entire trees of endpoints you are not interested in as well as eliminating partial traces if a span in the chain is ignored but calls out to other endpoints which are recorded as children of ROOT instead of the actual parent.
Enabling Node.js Agent log
Node.js agent uses debug framework for output log, and you can activate the log before you deploy the application currently.
You can set the logging level as follows:
- info
- debug
- warn
- error
Enabling log rotation
By default log rotation is enabled with max size 5MB and max files 7 days. You can change this by setting env SS_AGENT_LOGGING_MAXFILES & SS_AGENT_LOGGING_MAXSIZE.
- SS_AGENT_LOGGING_MAXSIZE
Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number.
- SS_AGENT_LOGGING_MAXFILES
The maximum number of logs to keep. This can be a number of files or a number of days. If using days, add 'd' as the suffix.
Installing on a Docker
Agent Integrations in a Docker
For agent integrations in a docker, see Downloading the agent.
Adding the dependency download configuration in the Docker file
The Node SixthSense agent is hosted in Rakuten self-hosted private package manager. To download the package, do the following for authentication.
- Add the below code snippet in your docker file before the NPM Install command.
- This code will set the configuration to identify the SixthSense package registry. It also tells the dependency to download from this URL that you defined with the same name in the package.json file.
- https://artifacts-observability.sixthsense.rakuten.com/api/v4/projects/3/packages/npm/ -- the SixthSense package manager URL.
- _authToken' "PACKAGE_TOKEN"– Since the package is hosted in a private package manager it requires some authentication to identify the user. This auth token will be defined during the onboarding.
- For simplicity, the auth token is placed in the docker file. However, if you don’t wish to add in the docker file and push it to your version control repository, you can pass this auth token based on your credential management by setting the environment variable, passing the secrets from Jenkins CI/CD, and so on.
- Build your application with docker build and run the docker image/container. The agent is integrated with your application and you will start seeing the metrics in the SixthSense dashboard.
Pass the PACKAGE_TOKEN as build arguments.
Example for yarn
Example for NPM
Node.js supported libraries
There are some built-in plugins that support automatic instrumentation of NodeJS libraries. Following is a complete list:
Library | Plugin Name | |
---|---|---|
1 | Express | express |
2 | Axios | axios |
3 | MySQL | mysql |
4 | MySQL | mysql2 |
5 | PostgreSQL | pg |
6 | pg-cursor | pg-cursor |
7 | MongoDB | mongodb |
8 | Mongoose | mongoose |
9 | RabbitMQ | amqplib |
10 | redis | ioredis |