nodetracing
nodetracing copied to clipboard
Distributed tracking system implemented by the fully opentracing standard, committed to the simplest deployment, the lowest invasion, the fastest out of the box—完全支持opentracing的分布式追踪系统,致...
nodetracing
![nodetracing logo](https://raw.githubusercontent.com/cheneyweb/nodetracing/master/web/public/img/icons/mstile-150x150.png)
中文
Distributed tracking system which is a fully implementation of opentracing standard.
Design goals:
- Simplicy for deployment
- Non-invasion for development
- Out-of-the-box for most scenarios
-
nodetracing
- Project Origin
- Design Concept
-
Instructions
- 1、Implementation Steps
- 1.1、Quick Start - Standalone(PORT:3636,36361,36362)
- 1.2、Quick Start - WebUIServer(PORT:3636,36362)
- 1.3、Quick Start - TracingServer(PORT:36361)
- 1.4、ENV
- 2、Docker Swarm Cluster
- 3、Install probe
- 3.1、Probe initialization (first line of application entry)
- 3.2、Async automatic probe (support for async function)
- 3.3、Http-request automatic probe (axios)
- 3.4、Http-response automatic probe (koa/express)
- 3.5、Grpc-client automatic probe (original)
- 3.6、Grpc-server automatic probe (original)
- 3.7、Grpc-client automatic probe(x-grpc framewrok)
- 3.8、Grpc-server automatic probe(x-grpc framewrok)
- 4、Manual probe
- 4.1、HTTP remote manual probe
- 4.1、GRPC remote manual probe
- 5、Examples of Probe Use
- Support & Help
- License
Project Origin
Nodetracing is written in nodejs, base on opentracing-javascript API
Compare similar projects including:
These above titans are indeed powerful, but also cumbersome and rigid in some way, so an out-of-the-box, lightweight and flexible "swissgear" is more likely met my imagination about an advanced distributed tracking system. now here it is, the name is Nodetrcing.
Design Concept
Nodetracing will be as simple and efficient as possible from the perspective of developer and manager. Progressive is the ultimate goal
Written in nodejs, cross-platform, easy to start, and fully support container cluster deployment, with decoupled frontend and backend, planning to provide API aside from UI
Probe supports multiple language clients, automatic probes are preferred (less code intrusion), at this stage, priority support for automatic probes:
- nodejs(support:async function,axios,koa,express,grpc original,x-grpc framewrok)
- java(planing...)
Instructions
1、Implementation Steps
The deployment of a typical distributed tracking system consists of the following two steps:
- Start collection service standalone/cluster >
- Install probes for applications that need to be tracked >
Then, along with the running of the application, the tracking information is displayed by the visualized WebUI interface
1.1、Quick Start - Standalone(PORT:3636,36361,36362)
cd server && npm run standalone
open browser http://localhost:3636/nodetracing/web/index.html
1.2、Quick Start - WebUIServer(PORT:3636,36362)
cd server && npm run web
1.3、Quick Start - TracingServer(PORT:36361)
cd server && npm run server
1.4、ENV
#Visualization services can be started by setting up WEB ports
WEB_PORT=3636 #for start WebUI Server
#Tracking services need to set up RPC ports for receiving Spans and WEB service addresses for reporting Spans
REPORT_ADDR=localhost #required
RPC_PORT=36361 #option,default 36361
#Tracking service reporting interval
REPORT_INTERVAL=5000 #option,default 5000
#Service interface TOKEN key
TOKEN_KEY=tDTUusE2PWmKpIyK #option,default 123456
2、Docker Swarm Cluster
#docker compose
docker-compose -f "docker-compose.yml" up -d
#docker stack
docker stack deploy --prune -c docker-compose.yml nodetracing
3、Install probe
npm i nodetracing
3.1、Probe initialization (first line of application entry)
const nodetracing = require('nodetracing')
const tracer = new nodetracing.Tracer({
serviceName: 'S1', // required,name of service
rpcAddress: 'localhost',// required,address of tracing service
rpcPort: '36361', // option,port of tracing service,default:36361
auto: true, // option,is enable automatic tracking,default:false
stackLog: false, // option,is record detailed stack information (including code line number location, etc., memory consumption is large),default:false
maxDuration: 30000 // option,maximum function execution time (garbage collection interval),default:30000
})
After completing the loading of nodetracing, then you can choose the following automatic probe/manual probe depending on your service type...
3.2、Async automatic probe (support for async function)
async function func1(){
...
}
async function func2(){
...
}
func1 = nodetracing.aop(func1)
func2 = nodetracing.aop(func2)
...
3.3、Http-request automatic probe (axios)
axios.interceptors.request.use(nodetracing.axiosMiddleware())
3.4、Http-response automatic probe (koa/express)
//koa
app.use(nodetracing.koaMiddleware())
//express
app.use(nodetracing.expressMiddleware())
3.5、Grpc-client automatic probe (original)
const grpc = require('grpc')
const Service = grpc.loadPackageDefinition(...)[packageName][serviceName]
new Service("ip:port", grpc.credentials.createInsecure(), { interceptors: [nodetracing.grpcClientMiddleware()] })
3.6、Grpc-server automatic probe (original)
const grpc = require('grpc')
const interceptors = require('@echo-health/grpc-interceptors')
let server = new grpc.Server()
server = interceptors.serverProxy(this.server)
server.use(nodetracing.grpcClientMiddleware())
3.7、Grpc-client automatic probe(x-grpc framewrok)
const RPCClient = require('x-grpc').RPCClient
const rpcClient = new RPCClient({
port: 3333,
protosDir: "/grpc/protos/",
implsDir: "/grpc/impls/",
serverAddress: "localhost"
})
rpcClient.use(nodetracing.grpcClientMiddleware())
rpcClient.connect()
let result = await rpcClient.invoke('demo.User.login', { username: 'cheney', password: '123456' } , optionMeta?)
3.8、Grpc-server automatic probe(x-grpc framewrok)
const RPCServer = require('x-grpc').RPCServer
const rpcServer = new RPCServer({
port: 3333,
protosDir: "/grpc/protos/",
implsDir: "/grpc/impls/",
serverAddress: "localhost"
})
rpcServer.use(nodetracing.grpcServerMiddleware())
rpcServer.listen()
4、Manual probe
// Create Root Span
let parentSpan = tracer.startSpan('sp1')
// Set Tag
parentSpan.setTag('category', 'Root')
// Create Child Span
let childSpan = tracer.startSpan('csp1', { childOf: parentSpan })
// Set Log
childSpan.log({ event: 'waiting' })
// Finish Span
childSpan.finish()
parentSpan.finish()
4.1、HTTP remote manual probe
tracer.inject(parentSpan, nodetracing.FORMAT_HTTP_HEADERS, headers)
let parentSpan = tracer.extract(nodetracing.FORMAT_HTTP_HEADERS, headers)
4.1、GRPC remote manual probe
tracer.inject(parentSpan, nodetracing.FORMAT_GRPC_METADATA, metadata)
let parentSpan = tracer.extract(nodetracing.FORMAT_GRPC_METADATA, metadata)
5、Examples of Probe Use
client/example/app_koa.js
client/example/app_express.js
client/example/app_grpc.js
client/example/app_manual.js
client/example/example.js
cd client && npm run start
Support & Help
If nodetracing is helpful to you, I hope to get a Star of yours :)
License
Apache License 2.0