All Products
Search
Document Center

Application Real-Time Monitoring Service:Use SkyWalking to report Node.js application data

Last Updated:Mar 20, 2024

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

To obtain an endpoint of SkyWalking, perform the following steps:

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. On the page that appears, click the Access point information tab.

  3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

  4. Set the Client parameter to SkyWalking.

    Obtain an endpoint of SkyWalking in the Related Information column of the table in the lower part.

    SkyWalking接入点信息

    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

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.

Note

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.

The following table describes the third-party repositories that can be monitored by using skywalking-backend-js.

Repository

Plug-in

Built-in HTTP and HTTPS module

http / https

Express

express

Axios

axios

MySQL

mysql

MySQL

mysql2

PostgreSQL

pg

pg-cursor

pg-cursor

MongoDB

mongodb

Mongoose

mongoose

RabbitMQ

amqplib

Redis

ioredis

AWS2DynamoDB

aws-sdk

AWS2Lambda

aws-sdk

AWS2SNS

aws-sdk

AWS2SQS

aws-sdk

Sample code

For more information about the sample code repository, see skywalking demo at GitHub.

Use SkyWalking to instrument a Node.js application

  1. Run the following command to install the SkyWalking Node.js agent:

    npm install --save skywalking-backend-js
  2. Configure the SkyWalking Node.js agent in the Node.js project.

    const {default: agent} = require("skywalking-backend-js");
    agent.start({})
  3. 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>
  4. Restart the application.

References

Official website of Apache SkyWalking