This topic describes how to report the data of a Node.js application to Tracing Analysis.
Prerequisites
Jaeger dependencies are added to the package of the Node.js project.
"dependencies": {
"jaeger-client": "^3.12.0"
}
- Log on to the Tracing Analysis console. In the left-side navigation pane, click Cluster Configurations.
- On the Cluster Configurations tab, click the Access point information tab. Then, turn on Show Token for the Cluster Information parameter.
- Set the Client parameter to the client that you want to use to collect trace data.
- In the Related Information column of the table in the lower part, click the copy icon next to the endpoint that you want to use.
Note: If you deploy your application in an Alibaba Cloud production environment, select a Virtual Private Cloud (VPC) endpoint. Otherwise, select a public endpoint. Generally, use the endpoint of v2 for Zipkin. Use the endpoint of v1 only if you know Zipkin well.
Background information
The following figure shows how to report data without using the Jaeger agent.
The following figure shows how to report data by using the Jaeger agent.
Procedure
Complete sample code based on Express
const express = require("express");
const initTracer = require("jaeger-client").initTracer;
const app = express();
const config = {
serviceName: 'node-service',
sampler: {
type: "const",
param: 1
},
reporter: {
collectorEndpoint: "<endpoint>"
},
};
const tracer = initTracer(config);
app.all('*', function (req, res, next) {
req.span = tracer.startSpan("say-hello");
next();
});
app.get("/api", function (req, res) {
const span = req.span;
span.log({event: "timestamp", value: Date.now()});
req.span.finish();
res.send({code: 200, msg: "success"});
});
app.listen(3000, '127.0.0.1', function () {
console.log('start');
});