After you use SkyWalking to instrument an application and report the trace data to the Managed Service for OpenTelemetry console, Managed Service for OpenTelemetry starts to monitor the application. Then, you can view the monitoring data of the application, such as the application topology, traces, abnormal transactions, slow transactions, and SQL analysis. This topic describes how to use skywalking-backend-js to perform automatic instrumentation and report Node.js application data.
Prerequisites
Background information
SkyWalking is a popular application performance monitoring (APM) service developed in China. SkyWalking is designed for microservices, cloud-native architectures, and containers, such as Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.
skywalking-backend-js is the official Node.js agent repository of SkyWalking and can be connected to Node.js applications to monitor Node.js applications. You can use skywalking-backend-js to automatically instrument multiple third-party repositories, such as MySQL, Redis, and RabbitMQ.
skyapm-nodejs is an earlier version of the official Node.js agent repository and is discontinued. We recommend that you use skywalking-backend-js, the latest version of the official Node.js agent repository, to monitor Node.js applications.
Sample code
For more information about the sample code repository, see skywalking demo at GitHub.
Use SkyWalking to instrument a Node.js application
Run the following command to install the SkyWalking Node.js agent:
npm install --save skywalking-backend-js
Configure the SkyWalking Node.js agent in the Node.js project.
const {default: agent} = require("skywalking-backend-js"); agent.start({})
Configure the parameters of the SkyWalking Node.js agent.
You can configure parameters to hard code the SkyWalking Node.js agent into a Node.js project or configure the SkyWalking Node.js agent by defining environment variables.
Configure parameters to hard code the SkyWalking Node.js agent into a Node.js project
agent.start({ serviceName: <your-service-name>, // The service name, which is used to identify the application. serviceInstance: <your-service-instance-name>, // The name of the service instance. collectorAddress: <collector-backend-address>, // The endpoint of the collector. authorization: <collector-token> //The token that is used to access the collector. });
Configure the SkyWalking Node.js agent by defining environment variables
# <endpoint>: the endpoint of the collector. <token>: the authentication token of the collector. <service-name>: the application name. export SW_AGENT_COLLECTOR_BACKEND_SERVICES=<endpoint> export SW_AGENT_AUTHENTICATION=<token> export SW_AGENT_NAME=<service-name>
Restart the application.