fapspirit / axios-opentracing Goto Github PK
View Code? Open in Web Editor NEWAxios interceptor which traces your requests ๐
License: MIT License
Axios interceptor which traces your requests ๐
License: MIT License
Would it be possible to add an option to include the request params and data from the axios request? That would be helpful information to add to a trace. I think it would include a change here to add them, for example:
https://github.com/fapspirit/axios-opentracing/blob/master/src/index.ts#L47
I was thinking something like this?
if (config.params) {
span.setTag('http.params', config.params)
}
if (config.data) {
span.setTag('http.data', config.data)
}
I apply in Vue.js.
-axios.js
const { initTracer } = require("./tracing");
const tracer = initTracer("hello-world");
const axios = require('axios');
const createAxiosTracing = require('axios-opentracing').default;
// Create tracing applyer
const applyTracingInterceptors = createAxiosTracing(tracer);
// Create root span
const rootSpan = tracer.startSpan('api_http_call');
// Setup an axios instance
const API = axios.create({
baseURL: 'http://localhost:9041'
});
// Setup tracing interceptors
applyTracingInterceptors(API, { rootSpan });
export default API
// Create tracing applyer
const applyTracingInterceptors = createAxiosTracing(tracer);
// Create root span
const rootSpan = tracer.createSpan('api_http_call');
// Setup an axios instance
const API = axios.create({
baseURL: 'http://localhost:8082'
});
// Setup tracing interceptors
applyTracingInterceptors(API, { rootSpan });
// Make some requests
Promise.all([
API.get('/api/v1/scc/cst/csm/cstmInfr/cstmList')
]).then((response) => {
console.log(response.data);
rootSpan.finish();
});
export default API
-script in Vue File
import initTracer from '../../axios.js'
thrift.js:186 Uncaught TypeError: _fs2.default.readFileSync is not a function
at Object.<anonymous> (thrift.js:186)
at Object.<anonymous> (main.js:78140)
at __webpack_require__ (bootstrap 125c1d18ac9bee54c754:659)
at fn (bootstrap 125c1d18ac9bee54c754:85)
at Object.<anonymous> (remote_reporter.js:24)
at __webpack_require__ (bootstrap 125c1d18ac9bee54c754:659)
at fn (bootstrap 125c1d18ac9bee54c754:85)
at Object.<anonymous> (configuration.js:31)
at __webpack_require__ (bootstrap 125c1d18ac9bee54c754:659)
at fn (bootstrap 125c1d18ac9bee54c754:85)
Is this package still alive? If it is so, I would recommend to add axios
as dependency of this package into the package.json
.
I followed the example which using jaeger. But I got the following error. Is there anything I missed?
I use the exact same code following the sample
TypeError: tracer.createSpan is not a function
at Object.<anonymous> (/Users/kelvin.yue/Projects/project.scmp.tech/technology/system/poc/istio-tracing/node-app/dist/index.js:24:25)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
Hi Anton -
Just getting going trying to use the example for Express/Axios but running into some difficulties.
Here is the example (with a couple of minor changes that seemed to be needed)
const axios = require('axios'); // missing from example
const express = require('express');
const expressOpentracing = require('express-opentracing');
const { initTracer } = require('jaeger-client');
const createAxiosTracing = require('axios-opentracing');
let config = {
disable: true, // MISSING on read from env? Might need to set explicitly
};
// Setup tracer
const tracer = initTracer(config);
// Create tracing applyer
const applyTracingInterceptors = createAxiosTracing(tracer);
const app = express();
// Setup express tracer middleware
app.use(expressOpentracing({ tracer }));
app.get('/', (req, res) => {
// Setup an axios instance
const API = axios.create({
baseURL: 'http://localhost:3000',
});
applyTracingInterceptors(API, { span: req.span });
API.get('/').then(response => res.end(response.data));
});
When I run the test program I receive this message -
TypeError: createAxiosTracing is not a function
at Object.<anonymous> (/home/tiny/rpn-calc/opent.js:15:34)
running node 6.12.0 and and my dependencies look like -
"dependencies": {
"acorn": "^7.0.0",
"acorn-jsx": "^5.0.2",
"axios": "^0.19.0",
"axios-opentracing": "^0.1.3",
"chokidar": "^3.1.0",
"express": "^4.17.1",
"express-jaeger": "0.0.16",
"express-opentracing": "^0.1.1",
"express-winston": "^4.0.0",
"fast-check": "^1.16.3",
"i18n-2": "^0.7.3",
"jaeger-client": "^3.17.0",
"method-override": "^3.0.0",
"morgan": "^1.9.1",
"node-fetch": "^2.6.0",
"nunjucks": "^3.2.0",
"opentracing": "^0.14.4",
"serve-favicon": "^2.5.0",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.1.0",
"zipkin": "^0.19.0",
"zipkin-axios": "^0.2.1",
"zipkin-context-cls": "^0.19.0",
"zipkin-instrumentation-axios": "^0.1.0",
"zipkin-instrumentation-express": "^0.19.0",
"zipkin-transport-http": "^0.19.0"
},
Could be something I'm doing wrong, as I'm just getting rolling with Node and related. Any tips or direction would be appreciated.
Sandy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.