"use strict";const axios = require("axios").default;const express = require("express");const redis = require('./utils/redis');const dbHelper = require("./utils/db");const app = express();app.get("/remoteInvoke", async (req, res) => {const result = await axios.get("http://cloud.tencent.com");return res.status(200).send(result.data);});app.get("/redis", async(req, res) => {let queryRes = await redis.getKey("foo")res.json({ code: 200, result: queryRes})})app.get("/mysql", async(req, res) => {let select =select*from table_demo;await dbHelper.query(select);res.json({ code: 200, result: "mysql op ended"})})app.use(express.json());app.listen(8080, () => {console.log("Listening on http://localhost:8080");});
npm install --save @opentelemetry/apinpm install --save @opentelemetry/auto-instrumentations-node
export OTEL_TRACES_EXPORTER="otlp"export OTEL_RESOURCE_ATTRIBUTES='token=<token>,hostName=<hostName>'export OTEL_EXPORTER_OTLP_PROTOCOL='grpc'export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="<endpoint>"export OTEL_SERVICE_NAME="<serviceName>"export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"node main.js
<serviceName>: Application name. Multiple application processes connecting with the same serviceName are displayed as multiple instances under the same application in APM. The application name can be up to 63 characters and can only contain lowercase letters, digits, and the separator (-), and it must start with a lowercase letter and end with a digit or lowercase letter.<token>: The business system Token obtained in the preliminary steps.<hostName>: The hostname of this instance, which is the unique identifier of the application instance. It can usually be set to the IP address of the application instance.<endpoint>: The connect point obtained in the preliminary steps.myService as the application name, myToken as the business system Token, 192.168.0.10 as the hostname, and http://pl-demo.ap-guangzhou.apm.tencentcs.com:4317 as the example connect point. The complete start-up command is:export OTEL_TRACES_EXPORTER="otlp"export OTEL_RESOURCE_ATTRIBUTES='token=myToken,hostName=192.168.0.10'export OTEL_EXPORTER_OTLP_PROTOCOL='grpc'export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://pl-demo.ap-guangzhou.apm.tencentcs.com:4317"export OTEL_SERVICE_NAME="myService"export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"node main.js
https://localhost:8080/. In normal traffic cases, the connected application will be displayed in Application Performance Monitoring > Application list. Click Application name/ID to enter the application details page, then select Instance Analysis to view the connected application instance. Since there is some latency in processing observable data, if the application or instance is not found in the console after connecting, wait about 30 seconds.const opentelemetry = require("@opentelemetry/api")app.get("/attr", async(req, res) => {const tracer = opentelemetry.trace.getTracer('my-service-tracer');tracer.startActiveSpan('new internal span', span => {span.addEvent("Acquiring lock", {'log.severity':'error','log.message':'data node found',})span.addEvent("Got lock, doing work...", {'log.severity':'11111','log.message':'2222222','log.message1':'3333333',})span.addEvent("Unlocking")span.end();});res.json({ code: 200, msg: "success" });})
Feedback