pinpoint-node-agent icon indicating copy to clipboard operation
pinpoint-node-agent copied to clipboard

plugins中的express插件bug

Open fernandou opened this issue 9 years ago • 6 comments

你好: 1)那个express插件的express.Route.prototype.method(get,post...)好像没有考虑到下面的情况 app.get(fn1,fn2...);就是说回调函数可以有很多个,而现在的插件只考虑到一个回调函数,是吗? 2)请教一下koa插件这么写?都是中间件,监听每个中间件的时间好像没有意义

fernandou avatar Nov 18 '16 02:11 fernandou

hi: 1) 当初是 考虑到内部使用的express项目 都只是用 app.method(callback),所以针对性的开发了插件。就只考虑第一个callback。 可以改写method,判断参数的callback个数,分别改写。 2) koa没接触过,需要看下源码 怎么实现,需要知道执行业务逻辑的函数,中间件其实没必要监控,只需要监控业务逻辑,也就是直接改写 最后一个执行用户业务的函数即可。类似express,改写method,改写其callback即可。

在 2016年11月18日 上午10:15,fernandou [email protected]写道:

你好: 1)那个express插件的express.Route.prototype.method(get,post...)好像没有考虑到下面的情况 app.get(fn1,fn2...);就是说回调函数可以有很多个,而现在的插件只考虑到一个回调函数,是吗? 2)请教一下koa插件这么写?都是中间件,监听每个中间件的时间好像没有意义

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/peaksnail/pinpoint-node-agent/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqe3_qFYqeuRziiSUaQgXwoE-rsbhy7ks5q_QpLgaJpZM4K2C6P .

peaksnail avatar Nov 18 '16 06:11 peaksnail

好的,谢谢

fernandou avatar Nov 18 '16 09:11 fernandou

我觉得可以去研究一下koa,因为koa的中间件都是构造器函数,不是一般的回调函数,所以不知从何下手

fernandou avatar Nov 18 '16 09:11 fernandou

嗯嗯,现在内部新的项目会使用koa,如果有需求的话,回去研究下

peaksnail avatar Nov 19 '16 03:11 peaksnail

目前koa插件还没有开发计划。

看了下koa的一些实例,发现和express类似,当前express 也是改写了router相关方法,如get,put等, koa中也有koa-router,和express 一样,我理解如果有使用这个中间件的话,可以参考下express,改写相关方法。其他的话,可以直接改写下业务逻辑。

对于koa,需要了解下源码,针对具体的方法进行改写,如果有什么问题,欢迎讨论

peaksnail avatar Dec 09 '16 09:12 peaksnail

1 在需要的函数中debug 下确认具体的函数类型,普通函数或generator 2 目前发现koa在正常使用情况下,使用的是 generator,那么其修改代码为 假设 需要修改函数为middleware(为generator)

var original = middleware;
middlerware = function *(){
  //track
  yield *original.apply(this, arguments);
}

如果确认是普通函数(可能使用babel,通过babel转码后可能出现的情况)的情况,那么修改的方法就和原来的一样

peaksnail avatar Jun 18 '17 02:06 peaksnail