- Ref:
https://github.com/jaegertracing/jaeger-client-node
const { initTracer } = require('jaeger-client');
const config = {
serviceName: 'your-service-name': String,
reporter: {
name: 'your-service-name-reporter' : String,
logSpans: true,
agentHost: 'your-reporter-host': String,
agentPort: 'your-report-port': Number
},
sampler: {
type: 'const',
param: 1.0
}
};
const options = {
tags: {
'service': 'your-service-tag': String,
'version': 'your-service-version': String,
}
}
module.exports = initTracer(config,options);
example:
import { initTracer } from "jaeger-client";
const config = {
serviceName: "pricer",
reporter: {
name: "pricer-reporter",
logSpans: true,
agentHost: process.env.JAEGER_AGENT_HOST || "localhost",
agentPort: process.env.JAEGER_AGENT_PORT || 6832
},
sampler: {
type: "const",
param: 1.0
}
};
const options = {
tags: {
service: "pricer",
version: process.env.npm_package_version || "1.0.0"
}
};
export default initTracer(config, options);
const jaeger = require("path-to-lib/jaeger.js");
const JaegerMiddleware = require("@chototoss/jaeger-client-nodejs");
const jaegerMiddleware = new JaegerMiddleware(jaeger);
module.exports = jaegerMiddleware;
After created, your structure should look like
├── libs
│ └── jaeger.js
├── middlewares
│ └── jaeger-middleware.js
├── package.json
├── routes
│ └── index.js
├── server.js
└── workers
└── main-worker.js
app.js
const jaegerMiddleware = require("path-to-middleware/jaeger-middleware.js");
app.use(jaegerMiddleware.handleLogBeforeResponse);
app.use(
`your_route_prefix`,
jaegerMiddleware.createSpanAfterReceivedRequest,
your_router
);
alternative ways to use
const jaegerMiddleware = require("path-to-middleware/jaeger-middleware.js");
app.use(
`your_end_point`,
jaegerMiddleware.handleLogBeforeResponse,
jaegerMiddleware.createSpanAfterReceivedRequest,
your_end_point_handler
);
main-worker.js
const jaegerMiddleware = require("path-to-middleware/jaeger-middleware.js");
const span = jaegerMiddleware.initSpanForWorker("worker-name",data,data.headers);
span.log(something)
span.finish()
- Please contact Son Nguyen - [email protected]