gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:09:46 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com