2016-08-11 53 views
0

我有一个使用node.js,koa,koa-router的应用程序。 我想添加newrelic到我的应用程序,但它不支持koa。如何在节点上配置newrelic + koa应用程序

所以我试图利用koa-newrelic(https://github.com/AfterShip/koa-newrelic),但它仍然无法正常工作。

我仍然得到/*所有交易。

谁有这方面的经验?

+0

舍利你试过KOA-或NewRelic的KOA -router-NewRelic的? –

+0

是的,但它在那个时候不起作用。我不确定它现在是否有效。 –

回答

1

我的同事帮助我解决这个问题。

的解决方案是低于

1.declare定制兴亚新来的

//****************** myKoaNewRelic.js ***************** 
'use strict' 

module.exports = function monitor(router, newrelic) { 
    return function* monitor(next) { 
    const route = this.params[0] 
    for (const layer of router.stack) { 
     if (layer.path !== '(.*)') { 
     const method = (layer.methods.indexOf('HEAD') !== -1) ? layer.methods[1] : layer.methods[0] 
     if (route.match(layer.regexp) && method === this.request.method) { 
      newrelic.setControllerName(layer.path, method) 
     } 
     } 
    } 
    yield next 
    } 
} 

2.更新主要index.js这样

//****************** index.js ***************** 
'use strict'  

const newrelic = require('newrelic') 
const koaNewrelic = require('./myKoaNewRelic') 
const app = require('koa')() 
const router = require('koa-router')() 

router.use(koaNewrelic(router, newrelic)) 

// DO SOME STUFF 
相关问题