whatap 0.4.90 → 0.4.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/observers/socket.io-observer.js +28 -119
- package/package.json +2 -2
|
@@ -4,142 +4,51 @@
|
|
|
4
4
|
* can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var MeterSocketio = require('../counter/meter/meter-socket.io')
|
|
8
|
-
TraceContextManager = require('../trace/trace-context-manager'),
|
|
9
|
-
SocketStep = require('../step/socket-step'),
|
|
10
|
-
conf = require('../conf/configure'),
|
|
11
|
-
IPUtil = require('../util/iputil'),
|
|
12
|
-
Logger = require('../logger');
|
|
13
|
-
const {callback} = require("pg/lib/native/query");
|
|
14
|
-
const {Detector: URLPatternDetector} = require("whatap/lib/trace/serviceurl-pattern-detector");
|
|
15
|
-
const HashUtil = require("whatap/lib/util/hashutil");
|
|
16
|
-
const DataTextAgent = require("whatap/lib/data/datatext-agent");
|
|
17
|
-
const ResourceProfile = require("whatap/lib/util/resourceprofile");
|
|
18
|
-
const MeterUsers = require("whatap/lib/counter/meter/meter-users");
|
|
19
|
-
const UserIdUtil = require("whatap/lib/util/userid-util");
|
|
20
|
-
const MessageStep = require("whatap/lib/step/message-step");
|
|
21
|
-
const Hexa32 = require("whatap/lib/util/hexa32");
|
|
22
|
-
const ProfilePack = require('../pack/profile-pack');
|
|
23
|
-
const TxRecord = require('../service/tx-record');
|
|
24
|
-
const DateUtil = require('../util/dateutil');
|
|
25
|
-
const SecurityMaster = require('../net/security-master');
|
|
26
|
-
const DataProfileAgent = require('../data/dataprofile-agent');
|
|
27
|
-
const MeterService = require('../counter/meter/meter-service').MeterService;
|
|
7
|
+
var MeterSocketio = require('../counter/meter/meter-socket.io');
|
|
28
8
|
|
|
29
9
|
var SocketIOObserver = function(agent){
|
|
30
10
|
this.agent = agent;
|
|
31
11
|
this.packages = ['socket.io'];
|
|
32
12
|
};
|
|
33
13
|
|
|
34
|
-
SocketIOObserver.prototype.inject = function
|
|
35
|
-
if (mod.__whatap_observe__) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
mod.__whatap_observe__ = true;
|
|
39
|
-
Logger.initPrint("SocketIOObserver");
|
|
40
|
-
if (conf.trace_background_socket_enabled === false) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
14
|
+
SocketIOObserver.prototype.inject = function( mod ){
|
|
44
15
|
var self = this;
|
|
45
16
|
var aop = self.agent.aop;
|
|
46
17
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
SocketIOObserver.prototype.__createTransactionObserver = function (callback) {
|
|
53
|
-
var self = this;
|
|
54
|
-
|
|
55
|
-
return function (){
|
|
56
|
-
TraceContextManager._asyncLocalStorage.run(initCtx(), () => {
|
|
57
|
-
var ctx = TraceContextManager._asyncLocalStorage.getStore();
|
|
58
|
-
if(!ctx) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
MeterSocketio.connected(1);
|
|
63
|
-
|
|
64
|
-
var host;
|
|
65
|
-
const socket = arguments[0];
|
|
66
|
-
const address = socket.handshake.address;
|
|
67
|
-
if(address && address.includes(':')){
|
|
68
|
-
host = address.substring(address.lastIndexOf(':')+1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
ctx.socket_connecting = true;
|
|
72
|
-
|
|
73
|
-
ctx.footprint('Socket Connecting: ' + host);
|
|
74
|
-
|
|
75
|
-
var step = new SocketStep();
|
|
76
|
-
step.start_time = ctx.getElapsedTime();
|
|
77
|
-
step.ipaddr = Buffer.from(IPUtil.stringToBytes(host));
|
|
78
|
-
// step.port = port;
|
|
79
|
-
|
|
80
|
-
ctx.socket_connecting = false;
|
|
81
|
-
step.elapsed = ctx.getElapsedTime() - step.start_time;
|
|
82
|
-
ctx.profile.push(step);
|
|
83
|
-
|
|
84
|
-
ctx.footprint('Socket Connecting Done');
|
|
85
|
-
|
|
86
|
-
self.__endTransaction(null, ctx);
|
|
87
|
-
|
|
88
|
-
return;
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
SocketIOObserver.prototype.__endTransaction = function(error, ctx) {
|
|
94
|
-
try {
|
|
95
|
-
var profile = new ProfilePack();
|
|
96
|
-
var wtx = new TxRecord();
|
|
97
|
-
wtx.endTime = DateUtil.currentTime();
|
|
98
|
-
profile.time = wtx.endTime;
|
|
99
|
-
wtx.elapsed = ctx.getElapsedTime();
|
|
100
|
-
|
|
101
|
-
ctx.service_hash = HashUtil.hashFromString(ctx.service_name);
|
|
102
|
-
DataTextAgent.SERVICE.add(ctx.service_hash, ctx.service_name);
|
|
103
|
-
|
|
104
|
-
wtx.service = ctx.service_hash;
|
|
105
|
-
wtx.cpuTime = ResourceProfile.getCPUTime() - ctx.start_cpu;
|
|
106
|
-
wtx.malloc = ResourceProfile.getUsedHeapSize()-ctx.start_malloc;
|
|
107
|
-
if(wtx.malloc < 0) { wtx.malloc = 0; }
|
|
108
|
-
wtx.status = 2;
|
|
109
|
-
|
|
110
|
-
MeterService.add(wtx.service, wtx.elapsed,
|
|
111
|
-
wtx.errorLevel, ctx.mcaller_pcode, ctx.mcaller_okind, ctx.mcaller_oid);
|
|
18
|
+
if(mod.__whatap_observe__) { return; }
|
|
19
|
+
mod.__whatap_observe__ = true;
|
|
112
20
|
|
|
113
|
-
|
|
114
|
-
|
|
21
|
+
aop.after(mod.prototype, ['listen','attach'], function(obj, args, ret) {
|
|
22
|
+
if (!ret.sockets) return;
|
|
115
23
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
DataProfileAgent.sendProfile(ctx, profile, false);
|
|
119
|
-
ctx = null;
|
|
120
|
-
}, 100);
|
|
24
|
+
aop.before(ret.sockets, ['on', 'addListener'], function(obj, args) {
|
|
25
|
+
if (args[0] !== 'connection') return;
|
|
121
26
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
TraceContextManager.end(ctx._id);
|
|
125
|
-
ctx = null;
|
|
126
|
-
}
|
|
27
|
+
aop.functionHook(args, -1, function(obj, args) {
|
|
28
|
+
if (!args[0]) return; //no client socket
|
|
127
29
|
|
|
128
|
-
|
|
30
|
+
var socket = args[0];
|
|
129
31
|
|
|
130
|
-
|
|
131
|
-
const ctx = TraceContextManager.start();
|
|
132
|
-
if (!ctx) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
32
|
+
MeterSocketio.connected(1);
|
|
135
33
|
|
|
136
|
-
|
|
137
|
-
|
|
34
|
+
socket.on('disconnect', function() {
|
|
35
|
+
MeterSocketio.disconnected();
|
|
36
|
+
});
|
|
138
37
|
|
|
139
|
-
|
|
140
|
-
|
|
38
|
+
aop.before(socket, ['emit', 'send'], function(obj, args) {
|
|
39
|
+
if (args[0] === 'newListener') return;
|
|
40
|
+
MeterSocketio.send(null, args);
|
|
41
|
+
});
|
|
141
42
|
|
|
142
|
-
|
|
43
|
+
aop.before(socket, ['on', 'addListener'], function(obj, args) {
|
|
44
|
+
if (args[0] === 'disconnect') return;
|
|
45
|
+
aop.functionHook(args, -1, function (obj, args) {
|
|
46
|
+
MeterSocketio.receive(null, args[0]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
143
52
|
}
|
|
144
53
|
|
|
145
54
|
exports.SocketIOObserver = SocketIOObserver;
|
package/package.json
CHANGED