node.js - 新的遗迹网络交易出现在根目录下

标签 node.js newrelic

我正在使用 node.js 代理来处理新的遗迹。我正在使用 Node.js 自定义工具来监视 socket.io,新的遗留 Web 事务出现在根目录下,并且没有数据可见,因为我无法监视 socket.io。以下是交易根路径下的输出

明细表

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>

最佳答案

问题出在新的遗迹模块版本中,有两个建议。

First, upgrade the Node.js agent to v2.2.0

此版本包含错误修复,应该可以解决您遇到的问题。

Second, move nr = require('newrelic'); to the top of the requires.

这可以确保代理在代码有机会启动之前捕获应用程序中的所有内容。如果没有这个,另一个要求中的代码可以在代理有机会注入(inject)其方法之前启动,从而导致无法跟踪这些方法。

关于node.js - 新的遗迹网络交易出现在根目录下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45912440/

相关文章:

node.js - 游标 batchSize 如何在 node-mongodb-native 驱动程序中工作?

javascript - 新遗迹和 react

centos - 将 New Relic 与 Celery 集成

node.js - 如何忽略 New Relic 仪表板中的特定错误

javascript - 转换为 mp3 完成后如何解决此 promise ( Fluent-ffmpeg )

node.js - 如何将表的最大 id 值分配给 Node.js 中的变量

mysql - Visual Studio 2013 MySQL 模块安装失败

ruby-on-rails - 有人会怎么写像 Newrelic 这样的东西,它是低级代码,即内核?

javascript - 有没有办法只使用 New Relic 的 RUM 功能?

node.js - socket.io 广播太多数据包