Zipkin-1.19.0学习系列2:Nodejs范例

2017-01-11 15:22:28来源:oschina作者:强子哥哥人点击

下面需要研究Nodejs的例子,找了下zipkin的装备库,看到有一个


http://zipkin.io/pages/existing_instrumentations


分为自家研发版 vs 社区吃瓜群众版,


---在里面找到一个js的库,https://github.com/openzipkin/zipkin-js


下面开始研究Nodejs如何上报信息。


http://stackoverflow.com/questions/39014203/is-it-possible-to-modify-polymer-iron-ajax-element-to-use-cujojs-rest
https://github.com/openzipkin/zipkin-js/tree/master/packages/zipkin-instrumentation-cujojs-rest

====================================================


按照官方的说法,先执行


npm install zipkin --save


===然后, 找到了2个可能有帮助的库


https://github.com/openzipkin/zipkin-js/tree/master/packages/zipkin-transport-http


&


https://github.com/openzipkin/zipkin-js/tree/master/packages/zipkin-instrumentation-cujojs-rest


感觉zipkin-instrumentation-cujojs-rest比较有戏。


先安装这个库


npm install zipkin-instrumentation-cujojs-rest


npm install zipkin-transport-http


npm install --save rest


然后,例子参考:http://stackoverflow.com/questions/39014203/is-it-possible-to-modify-polymer-iron-ajax-element-to-use-cujojs-rest


源码如下:


const {Tracer,BatchRecorder,ExplicitContext} = require('zipkin');
const {HttpLogger}= require('zipkin-transport-http')
const {restInterceptor} = require('zipkin-instrumentation-cujojs-rest');
const rest= require('rest');
console.log("1---");
const ctxImpl = new ExplicitContext();
const recorder = new BatchRecorder({
logger: new HttpLogger({
endpoint: 'http://localhost:9411/api/v1/spans'
})
});
//
const tracer = new Tracer({ctxImpl, recorder}); // configure your tracer properly here
const nameOfRemoteService = 'youtube';
const client = rest.wrap(restInterceptor, {tracer, remoteServiceName: nameOfRemoteService});
////
//
//
var http= require('http');
http.createServer(function (req, res) {// Your application code here
client
(
{
method:'GET',
path: 'http://www.163.com/'
}
)
.then
(
success => {
console.log('got result from YouTube');
},
error => {
console.error('Error', error);
}
);// Your application code end
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World/n');
}
)
.listen(1337, "0.0.0.0");
console.log('Server running at http://0.0.0.0:1337/');

在zipkin的界面上可以看到有数据产生,


然后还有一个问题就是ID的传递,抓包如下:




证明,ID是可以自动传递到下一个进程的。


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台