出现在根目录下的新遗物Web事务

我正在使用node.js代理为新的文物。 我正在使用Node.js自定义检测来监视socket.io,新的文物web事务出现在根下,没有数据是可见的,因为我无法监视socket.io。 以下是交易根path下的输出

分解表

Category Segment % Time Avg calls (per txn) Avg time (ms) WebTransaction Root path 100.0 1.0 2,150 

服务器代码

 var http = require('http'), fs = require('fs'), nr = require('newrelic'), index = fs.readFileSync(__dirname + '/sock_client.html'); var app = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(index); }); // Socket.io server listens to our app var io = require('socket.io').listen(app); // Send current time to all connected clients function sendTime() { io.emit('time', { time: new Date().toJSON() }); } // Send current time every 10 secs setInterval(sendTime, 10000); // Emit welcome message on connection io.on('connection', function(socket) { // Use socket to communicate with this particular client only, sending it it's own id socket.emit('welcome', { message: 'Welcome!', id: socket.id }); socket.on('rings', function(data){ nr.startWebTransaction('websocket/ping/test_v3', function transactionHandler() { socket.emit('pong', { message: 'Welcome!' }); console.log(data); nr.addCustomParameters({ "Discount Code": "Summer Super Sale", "Item Code": 31456 }); }); }); socket.on('pings', function(data){ nr.startWebTransaction('websocket/ping/test_v5', function transactionHandler() { let trans = nr.getTransaction(); someAsyncBeha("console.log", function(){ trans.end(); }) console.log(data); }); }); }); function someAsyncBeha(data, cb){ setTimeout(function() { console.log("Goodbye!"); console.log(data); cb(); }, 5000); }; 

客户代码

 <!doctype html> <html> <head> <link rel="shortcut icon" href="/favicon.png"> <script src='/socket.io/socket.io.js'></script> <script> var socket = io(); socket.on('welcome', function(data) { addMessage(data.message); // Respond with a message including this clients' id sent from the server socket.emit('rings', {data: 'foo!', id: data.id}); }); socket.on('time', function(data) { addMessage(data.time); socket.emit('pings', {data: 'foo!', id: data.time}); }); socket.on('error', console.error.bind(console)); socket.on('message', console.log.bind(console)); socket.on('pong', console.log.bind(console)); function addMessage(message) { var text = document.createTextNode(message), el = document.createElement('li'), messages = document.getElementById('messages'); el.appendChild(text); messages.appendChild(el); } </script> </head> <body> <ul id='messages'></ul> </body> </html> 

问题是在新的文物模块版本中,有两个build议。

首先,将Node.js代理升级到v2.2.0

这个版本包括一个错误修复,可以解决你所看到的问题。

其次,移动nr = require('newrelic'); 到要求的顶部。

这确保代理在代码有机会启动之前捕获应用程序中的所有内容。 如果没有这个,那么在代理有机会注入其方法之前,另一个代码需要启动,导致没有跟踪这些方法。