whatap 0.4.88 → 0.4.90
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/conf/config-default.js +2 -0
- package/lib/control/packagectr-helper.js +32 -56
- package/lib/net/security-master.js +8 -7
- package/lib/observers/http-observer.js +56 -9
- package/lib/observers/mongoose-observer.js +133 -57
- package/lib/observers/net-observer.js +0 -1
- package/lib/observers/socket.io-observer.js +119 -29
- package/lib/step/method-stepx.js +0 -2
- package/package.json +2 -2
- package/logs/whatap-20231212.log +0 -10
|
@@ -137,6 +137,8 @@ var ConfigDefault = {
|
|
|
137
137
|
"status_ignore_set": str('status_ignore_set', ''),
|
|
138
138
|
"httpc_status_ignore_set": str('httpc_status_ignore_set', ''),
|
|
139
139
|
"trace_sql_normalize_enabled" : true,
|
|
140
|
+
"httpc_not_found_ignore": bool('httpc_not_found_ignore', false),
|
|
141
|
+
"httpc_not_found_ignore_time": num('httpc_not_found_ignore', 300000),
|
|
140
142
|
|
|
141
143
|
//2017.05.02 AUTO ONAME
|
|
142
144
|
"auto_oname_enabled" : bool('auto_oname_enabled',false),
|
|
@@ -20,69 +20,43 @@ var loadedPackageList = [],
|
|
|
20
20
|
dependencies = [];
|
|
21
21
|
|
|
22
22
|
var PackageCtrHelper = function() {};
|
|
23
|
-
PackageCtrHelper.addPackage = function(
|
|
23
|
+
PackageCtrHelper.addPackage = function(realPath){
|
|
24
24
|
try {
|
|
25
|
-
if
|
|
26
|
-
|
|
27
|
-
loadedPackageList.push(name);
|
|
28
|
-
}
|
|
29
|
-
} else if(callPath != null) {
|
|
30
|
-
var callerPath = path.join(callPath, '..');
|
|
31
|
-
var filename = name;
|
|
32
|
-
var realPath = callerPath;
|
|
33
|
-
try {
|
|
34
|
-
realPath = fs.realpathSync(path.join(callerPath, filename));
|
|
35
|
-
} catch(e) {
|
|
36
|
-
try {
|
|
37
|
-
filename += '.js';
|
|
38
|
-
realPath = fs.realpathSync(path.join(callerPath, filename));
|
|
39
|
-
} catch(e) {
|
|
40
|
-
return Logger.printError("WHATAP-511", "PackageControler helper", e, false);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
loadedPackages[realPath] = pkg;
|
|
25
|
+
if(!loadedPackages[realPath]){
|
|
26
|
+
loadedPackages[realPath] = require(realPath);
|
|
44
27
|
}
|
|
45
28
|
} catch(e) {
|
|
46
29
|
return Logger.printError("WHATAP-512", "PackageControler helper", e, false);
|
|
47
30
|
}
|
|
48
31
|
};
|
|
49
|
-
PackageCtrHelper.dynamicHook = function(realPath, funcName) {
|
|
50
|
-
if(
|
|
32
|
+
PackageCtrHelper.dynamicHook = function(pkg, realPath, funcName) {
|
|
33
|
+
if(!pkg || !funcName) {
|
|
51
34
|
return;
|
|
52
35
|
}
|
|
53
|
-
if(loadedPackages[realPath]){
|
|
54
|
-
var pkg = loadedPackages[realPath];
|
|
55
36
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
_aop.before(pkg, functName, function(){
|
|
82
|
-
// transaction step
|
|
83
|
-
}, false);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
37
|
+
var Interceptor = require('../core/interceptor').Interceptor;
|
|
38
|
+
var _aop = new Interceptor(null);
|
|
39
|
+
_aop.both(pkg, funcName,
|
|
40
|
+
function(obj, args, lctx){
|
|
41
|
+
// transaction step
|
|
42
|
+
var ctx = lctx.context;
|
|
43
|
+
if(!ctx) { return; }
|
|
44
|
+
|
|
45
|
+
var msg = realPath + ' ' + funcName;
|
|
46
|
+
var hash = HashUtil.hashFromString(msg);
|
|
47
|
+
var step = new MethodStep();
|
|
48
|
+
DataTextAgent.METHOD.add(hash, msg);
|
|
49
|
+
step.hash = hash;
|
|
50
|
+
step.start_time = ctx.getElapsedTime();
|
|
51
|
+
pkg.__whatap_step__ = step;
|
|
52
|
+
},
|
|
53
|
+
function(obj, args, ret, lctx){
|
|
54
|
+
var ctx = lctx.context;
|
|
55
|
+
if(!ctx) { return; }
|
|
56
|
+
var step = pkg.__whatap_step__;
|
|
57
|
+
step.elapsed = ctx.getElapsedTime() - step.start_time;
|
|
58
|
+
ctx.profile.add(step);
|
|
59
|
+
});
|
|
86
60
|
};
|
|
87
61
|
PackageCtrHelper.getLoadedPackageList = function(filter){
|
|
88
62
|
return loadedPackageList;
|
|
@@ -142,9 +116,11 @@ conf.on('hook_method_patterns', function (value) {
|
|
|
142
116
|
root = root.substr(0, root.indexOf('/bin'));
|
|
143
117
|
}
|
|
144
118
|
var real_path = root + relative_path;
|
|
145
|
-
PackageCtrHelper.
|
|
119
|
+
PackageCtrHelper.addPackage(real_path);
|
|
120
|
+
if(loadedPackages[real_path]) {
|
|
121
|
+
PackageCtrHelper.dynamicHook(loadedPackages[real_path], real_path, method);
|
|
122
|
+
}
|
|
146
123
|
});
|
|
147
|
-
|
|
148
124
|
});
|
|
149
125
|
|
|
150
126
|
module.exports = PackageCtrHelper;
|
|
@@ -70,7 +70,7 @@ var SecurityMaster = {
|
|
|
70
70
|
OidUtil.setType(process.env.name || Configuration.getProperty("whatap.type", "NODE"));
|
|
71
71
|
|
|
72
72
|
var name_pattern;
|
|
73
|
-
if(Configuration.getProperty('whatap_micro_enabled') === true){
|
|
73
|
+
if(Configuration.getProperty('whatap_micro_enabled', false) === true){
|
|
74
74
|
name_pattern = process.env.WHATAP_NAME || "{okind}-{ip2}-{ip3}";
|
|
75
75
|
}else if(require('cluster').isMaster){
|
|
76
76
|
name_pattern=process.env.WHATAP_NAME || "{type}-{ip2}-{ip3}";
|
|
@@ -90,8 +90,9 @@ var SecurityMaster = {
|
|
|
90
90
|
this.OKIND_NAME=null;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
if(Configuration.getProperty('whatap_micro_enabled') === false) {
|
|
93
|
+
if(Configuration.getProperty('whatap_micro_enabled', false) === false) {
|
|
94
94
|
var onodeStr= process.env.WHATAP_ONODE || Configuration.getProperty('whatap.onode');
|
|
95
|
+
console.log(onodeStr)
|
|
95
96
|
if(onodeStr && onodeStr.length>0){
|
|
96
97
|
this.ONODE = HashUtil.hashFromString(onodeStr);
|
|
97
98
|
this.ONODE_NAME=onodeStr;
|
|
@@ -107,7 +108,7 @@ var SecurityMaster = {
|
|
|
107
108
|
|
|
108
109
|
if (lastOid != this.OID) {
|
|
109
110
|
lastOid = this.OID;
|
|
110
|
-
|
|
111
|
+
require('../logger').print('WHATAP-968', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
|
|
111
112
|
}
|
|
112
113
|
},
|
|
113
114
|
setAgentOnameOid :function (oname, myIp) {
|
|
@@ -139,7 +140,7 @@ var SecurityMaster = {
|
|
|
139
140
|
this.OKIND_NAME=null;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
if(Configuration.getProperty('whatap_micro_enabled') === false) {
|
|
143
|
+
if(Configuration.getProperty('whatap_micro_enabled', false) === false) {
|
|
143
144
|
var onodeStr= process.env.WHATAP_ONODE || Configuration.getProperty('whatap.onode');
|
|
144
145
|
if(onodeStr && onodeStr.length>0){
|
|
145
146
|
this.ONODE = HashUtil.hashFromString(onodeStr);
|
|
@@ -149,7 +150,7 @@ var SecurityMaster = {
|
|
|
149
150
|
this.ONODE_NAME=null;
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
+
|
|
153
154
|
if (lastOid != this.OID) {
|
|
154
155
|
lastOid = this.OID;
|
|
155
156
|
require('../logger').print('WHATAP-168', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
|
|
@@ -169,14 +170,14 @@ var SecurityMaster = {
|
|
|
169
170
|
ProcessSeq('whatap').accessAuth(function(pseq){
|
|
170
171
|
if(!pseq){
|
|
171
172
|
return;
|
|
172
|
-
}
|
|
173
|
+
}
|
|
173
174
|
var conf = require('./../conf/configure');
|
|
174
175
|
conf.setProperty('node.clusterId', pseq);
|
|
175
176
|
if(cb) cb();
|
|
176
177
|
});
|
|
177
178
|
*/
|
|
178
179
|
}
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
}
|
|
181
182
|
};
|
|
182
183
|
|
|
@@ -35,7 +35,8 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
35
35
|
PluginLoaderManager = require('../plugin/plugin-loadermanager'),
|
|
36
36
|
Long = require('long'),
|
|
37
37
|
KeyGen = require('../util/keygen'),
|
|
38
|
-
Logger = require('../logger')
|
|
38
|
+
Logger = require('../logger'),
|
|
39
|
+
IntKeyLinkedMap = require("../util/intkey-linkedmap");
|
|
39
40
|
|
|
40
41
|
var _exts=new Set([".css",".js",".png", ".htm", ".html", ".gif", ".jpg", ".css", ".txt", ".ico"]);
|
|
41
42
|
|
|
@@ -50,6 +51,8 @@ var httpc_status_ignore = conf.getProperty('httpc_status_ignore', '');
|
|
|
50
51
|
var status_ignore_set = conf.getProperty('status_ignore_set', '');
|
|
51
52
|
var httpc_status_ignore_set = conf.getProperty('httpc_status_ignore_set', '');
|
|
52
53
|
var profile_error_step_enabled = conf.getProperty('profile_error_step_enabled', '');
|
|
54
|
+
var httpc_not_found_ignore = conf.getProperty('httpc_not_found_ignore', false);
|
|
55
|
+
var httpc_not_found_ignore_time = conf.getProperty('httpc_not_found_ignore_time', 300000);
|
|
53
56
|
conf.on('trace_http_client_ip_header_key', function(newProperty) {
|
|
54
57
|
configIpHeaderKey = newProperty;
|
|
55
58
|
});
|
|
@@ -92,6 +95,12 @@ conf.on('httpc_status_ignore_set', function (newProps) {
|
|
|
92
95
|
conf.on('profile_error_step_enabled', function (newProps) {
|
|
93
96
|
profile_error_step_enabled = newProps;
|
|
94
97
|
})
|
|
98
|
+
conf.on('httpc_not_found_ignore', function (newProps) {
|
|
99
|
+
httpc_not_found_ignore = newProps;
|
|
100
|
+
})
|
|
101
|
+
conf.on('httpc_not_found_ignore_time', function (newProps) {
|
|
102
|
+
httpc_not_found_ignore_time = newProps;
|
|
103
|
+
})
|
|
95
104
|
var staticConents = function (newProps) {
|
|
96
105
|
var x=new Set();
|
|
97
106
|
var words = !newProps?[]:newProps.split(',');
|
|
@@ -111,6 +120,9 @@ var staticConents = function (newProps) {
|
|
|
111
120
|
conf.on('web_static_content_extensions', staticConents);
|
|
112
121
|
staticConents(conf["web_static_content_extensions"]);
|
|
113
122
|
|
|
123
|
+
var httpc_not_found_ignore_map = null;
|
|
124
|
+
var httpc_not_found_ignore_url = [];
|
|
125
|
+
|
|
114
126
|
var HttpObserver = function(agent){
|
|
115
127
|
this.agent = agent;
|
|
116
128
|
this.packages = ['http','https'];
|
|
@@ -144,6 +156,17 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
|
|
|
144
156
|
if(ctx == null) { return; }
|
|
145
157
|
PluginLoaderManager.do('httpserviceend', ctx, req, res);
|
|
146
158
|
|
|
159
|
+
var not_found_ignore = httpc_not_found_ignore_url.includes(req.url);
|
|
160
|
+
if (httpc_not_found_ignore && !not_found_ignore && obj.statusCode === 404) {
|
|
161
|
+
const url_hash = HashUtil.hashFromString(req.url);
|
|
162
|
+
const currentTime = new Date().getTime();
|
|
163
|
+
|
|
164
|
+
if (!httpc_not_found_ignore_map) {
|
|
165
|
+
httpc_not_found_ignore_map = new IntKeyLinkedMap(500, 1).setMax(500);
|
|
166
|
+
}
|
|
167
|
+
updateNotFoundIgnoreMap(req.url, url_hash, currentTime);
|
|
168
|
+
}
|
|
169
|
+
|
|
147
170
|
ctx.isStaticContents = isStatic(req.url);
|
|
148
171
|
ctx.http_method = req.method;
|
|
149
172
|
if(conf.profile_http_querystring_enabled){
|
|
@@ -163,16 +186,11 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
|
|
|
163
186
|
var requestPath = '';
|
|
164
187
|
if(req.route && req.route.path)
|
|
165
188
|
requestPath = req.route.path;
|
|
166
|
-
var is_ignore;
|
|
167
|
-
if(ctx.is_httpc_error){
|
|
168
|
-
is_ignore = shouldIgnoreError(res.statusCode, requestPath, httpc_status_ignore, httpc_status_ignore_set);
|
|
169
|
-
} else {
|
|
170
|
-
is_ignore = shouldIgnoreError(res.statusCode, requestPath, status_ignore, status_ignore_set);
|
|
171
|
-
}
|
|
172
189
|
|
|
173
|
-
|
|
190
|
+
var shouldEndTransaction = shouldEndCurrentTransaction(not_found_ignore, ctx, res, req.route ? req.route.path : '');
|
|
191
|
+
if (shouldEndTransaction) {
|
|
174
192
|
self.__endTransaction(null, ctx, req, res);
|
|
175
|
-
else{
|
|
193
|
+
} else {
|
|
176
194
|
TraceContextManager.end(ctx._id);
|
|
177
195
|
ctx = null;
|
|
178
196
|
}
|
|
@@ -792,4 +810,33 @@ function shouldIgnoreError(statusCode, url, statusCodeIgnore, statusIgnoreSet) {
|
|
|
792
810
|
return false;
|
|
793
811
|
}
|
|
794
812
|
|
|
813
|
+
function updateNotFoundIgnoreMap(url, url_hash, currentTime) {
|
|
814
|
+
var ignore_value = httpc_not_found_ignore_map.get(url_hash) || {
|
|
815
|
+
count: 0, start_time: currentTime, last_time: currentTime, url: url
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
ignore_value.count++;
|
|
819
|
+
ignore_value.last_time = currentTime;
|
|
820
|
+
|
|
821
|
+
if ((ignore_value.last_time - ignore_value.start_time) > httpc_not_found_ignore_time) {
|
|
822
|
+
ignore_value = { count: 1, start_time: currentTime, last_time: currentTime, url: url };
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
if (ignore_value.count >= 50) {
|
|
826
|
+
httpc_not_found_ignore_url.push(url);
|
|
827
|
+
httpc_not_found_ignore_map.remove(url_hash);
|
|
828
|
+
Logger.print('WHATAP-610', "The ignore option for URL " + url + " is applied.", false);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
httpc_not_found_ignore_map.put(url_hash, ignore_value);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function shouldEndCurrentTransaction(not_found_ignore, ctx, res, requestPath) {
|
|
835
|
+
if (not_found_ignore) return false;
|
|
836
|
+
var is_ignore = ctx.is_httpc_error ?
|
|
837
|
+
shouldIgnoreError(res.statusCode, requestPath, httpc_status_ignore, httpc_status_ignore_set) :
|
|
838
|
+
shouldIgnoreError(res.statusCode, requestPath, status_ignore, status_ignore_set);
|
|
839
|
+
return !is_ignore;
|
|
840
|
+
}
|
|
841
|
+
|
|
795
842
|
exports.HttpObserver = HttpObserver;
|
|
@@ -3,81 +3,157 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
3
3
|
SqlStepX = require('../step/sql-stepx'),
|
|
4
4
|
DataTextAgent = require('../data/datatext-agent'),
|
|
5
5
|
HashUtil = require('../util/hashutil');
|
|
6
|
+
const DBCStep = require("whatap/lib/step/dbc-step");
|
|
7
|
+
const Logger = require("whatap/lib/logger");
|
|
6
8
|
|
|
7
9
|
var MongooseObserver = function (agent) {
|
|
8
10
|
this.agent = agent;
|
|
9
11
|
this.packages = ['mongoose'];
|
|
10
12
|
};
|
|
11
13
|
|
|
14
|
+
var dbc_step, dbc, conn_dbc_hash;
|
|
12
15
|
MongooseObserver.prototype.inject = function (mod, modName) {
|
|
13
16
|
|
|
14
17
|
var self = this;
|
|
15
|
-
|
|
16
18
|
var hookCommand = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'geoNear',
|
|
34
|
-
'geoSearch',
|
|
35
|
-
'populate'
|
|
19
|
+
"create", // Create: Create a new document
|
|
20
|
+
"insertMany", // Create: Create multiple documents at once
|
|
21
|
+
"find", // Read: Find documents that match criteria
|
|
22
|
+
"findById", // Read: Find a document by its ID
|
|
23
|
+
"findOne", // Read: Find the first document that matches criteria
|
|
24
|
+
"countDocuments", // Read: Count the number of documents that match criteria
|
|
25
|
+
"distinct", // Read: Find distinct values for a given field
|
|
26
|
+
"updateMany", // Update: Update multiple documents that match criteria
|
|
27
|
+
"updateOne", // Update: Update a single document that matches criteria
|
|
28
|
+
"replaceOne", // Update: Replace one document with another
|
|
29
|
+
"findOneAndUpdate", // Update: Find the first document that matches criteria and update it
|
|
30
|
+
"findByIdAndUpdate", // Update: Find a document by its ID and update it
|
|
31
|
+
"deleteOne", // Delete: Delete a single document that matches criteria
|
|
32
|
+
"deleteMany", // Delete: Delete multiple documents that match criteria
|
|
33
|
+
"findOneAndDelete", // Delete: Find the first document that matches criteria and delete it
|
|
34
|
+
"findByIdAndDelete" // Delete: Find a document by its ID and delete it
|
|
36
35
|
];
|
|
37
36
|
|
|
38
|
-
self.agent.aop.
|
|
39
|
-
|
|
40
|
-
if(
|
|
37
|
+
self.agent.aop.after(mod, ['connect'] ,function (obj, args, ret) {
|
|
38
|
+
if(!args[0]) { return; }
|
|
39
|
+
if(dbc) { return; }
|
|
40
|
+
dbc = args[0];
|
|
41
|
+
conn_dbc_hash = HashUtil.hashFromString(dbc);
|
|
42
|
+
|
|
43
|
+
ret.then(data => {
|
|
44
|
+
self.agent.aop.both(data.Model, 'aggregate', function (_obj, _args, _lctx) {
|
|
45
|
+
var ctx = TraceContextManager.getCurrentContext();
|
|
46
|
+
if(!ctx) {return;}
|
|
47
|
+
|
|
48
|
+
if(dbc && conn_dbc_hash){
|
|
49
|
+
DataTextAgent.DBC.add(conn_dbc_hash, dbc);
|
|
50
|
+
DataTextAgent.METHOD.add(conn_dbc_hash, dbc);
|
|
51
|
+
DataTextAgent.ERROR.add(conn_dbc_hash, dbc);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var dbc_step = new DBCStep();
|
|
55
|
+
dbc_step.hash = conn_dbc_hash;
|
|
56
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
57
|
+
|
|
58
|
+
_lctx.dbc_step = dbc_step;
|
|
59
|
+
|
|
60
|
+
var sql_step = new SqlStepX();
|
|
61
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
62
|
+
_lctx.sql_step = sql_step;
|
|
63
|
+
}, function (_obj, _args, _ret, _lctx) {
|
|
64
|
+
var ctx = _lctx.context;
|
|
65
|
+
var dbc_step = _lctx.dbc_step;
|
|
66
|
+
var sql_step = _lctx.sql_step;
|
|
67
|
+
if(!ctx || !dbc_step || !sql_step) {return null;}
|
|
68
|
+
|
|
69
|
+
dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
70
|
+
ctx.profile.push(dbc_step);
|
|
71
|
+
|
|
72
|
+
ctx.footprint('Mongodb Command Start: ' + _ret.op );
|
|
41
73
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
const mongooseCollection = _ret._model;
|
|
75
|
+
try {
|
|
76
|
+
var sql = mongooseCollection.modelName + ' aggregate';
|
|
77
|
+
var param = "";
|
|
78
|
+
if(Array.isArray(_args[0])) {
|
|
79
|
+
_args[0].forEach(function (val, i) {
|
|
80
|
+
if(i > 0 && param.length > 0) {
|
|
81
|
+
param += ",";
|
|
82
|
+
}
|
|
83
|
+
if(val.hasOwnProperty('$match')) {
|
|
84
|
+
var keys = Object.keys(val['$match']);
|
|
85
|
+
param += keys;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if(val.hasOwnProperty('$group')) {
|
|
89
|
+
var keys = Object.keys(val['$group']);
|
|
90
|
+
param += keys;
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
sql += ' field=['+param+']';
|
|
95
|
+
|
|
96
|
+
sql_step.hash = HashUtil.hashFromString(sql);
|
|
97
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
98
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
99
|
+
DataTextAgent.SQL.add(sql_step.hash, sql);
|
|
100
|
+
ctx.profile.push(sql_step);
|
|
101
|
+
} catch(e) {
|
|
102
|
+
Logger.printError("WHATAP-611", "Mongodb query error", e, false);
|
|
103
|
+
sql_step = null;
|
|
47
104
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
self.agent.aop.both(data.Model, hookCommand, function (_obj, _args, _lctx) {
|
|
108
|
+
if(_args[0] && typeof _args[0] !== "object") { return; }
|
|
109
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
110
|
+
if(!ctx) { return; }
|
|
111
|
+
if(dbc && conn_dbc_hash){
|
|
112
|
+
DataTextAgent.DBC.add(conn_dbc_hash, dbc);
|
|
113
|
+
DataTextAgent.METHOD.add(conn_dbc_hash, dbc);
|
|
114
|
+
DataTextAgent.ERROR.add(conn_dbc_hash, dbc);
|
|
51
115
|
}
|
|
52
116
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
117
|
+
var dbc_step = new DBCStep();
|
|
118
|
+
dbc_step.hash = conn_dbc_hash;
|
|
119
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
120
|
+
|
|
121
|
+
_lctx.dbc_step = dbc_step;
|
|
122
|
+
|
|
123
|
+
var sql_step = new SqlStepX();
|
|
124
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
125
|
+
_lctx.sql_step = sql_step;
|
|
126
|
+
}, function (_obj, _args, _ret, _lctx) {
|
|
127
|
+
var ctx = _lctx.context;
|
|
128
|
+
var dbc_step = _lctx.dbc_step;
|
|
129
|
+
var sql_step = _lctx.sql_step;
|
|
130
|
+
if(!ctx || !dbc_step || !sql_step) {return null;}
|
|
131
|
+
|
|
132
|
+
dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
133
|
+
ctx.profile.push(dbc_step);
|
|
134
|
+
|
|
135
|
+
ctx.footprint('Mongodb Command Start: ' + _ret.op );
|
|
136
|
+
|
|
137
|
+
const mongooseCollection = _ret.mongooseCollection;
|
|
138
|
+
try {
|
|
139
|
+
var sql = mongooseCollection.modelName + ' ' + _ret.op ;//+ ': ' + JSON.stringify(Object.keys(args[0]));
|
|
140
|
+
if(_args[0]) { sql += ' field=' + JSON.stringify(Object.keys(_args[0])); }
|
|
141
|
+
if(_args[1]) { sql += ' value=' + JSON.stringify(Object.keys(_args[1])); }
|
|
142
|
+
|
|
143
|
+
sql_step.hash = HashUtil.hashFromString(sql);
|
|
144
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
145
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
146
|
+
DataTextAgent.SQL.add(sql_step.hash, sql);
|
|
147
|
+
ctx.profile.push(sql_step);
|
|
148
|
+
} catch(e) {
|
|
149
|
+
Logger.printError("WHATAP-611", "Mongodb query error", e, false);
|
|
150
|
+
sql_step = null;
|
|
56
151
|
}
|
|
57
152
|
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sql_step.hash = HashUtil.hashFromString(sql);
|
|
63
|
-
sql_step.start_time = ctx.getElapsedTime();
|
|
64
|
-
sql_step.dbc = 0;
|
|
65
|
-
|
|
66
|
-
DataTextAgent.SQL.add(sql_step.hash, sql);
|
|
67
|
-
ctx.profile.push(sql_step);
|
|
68
|
-
|
|
69
|
-
self.agent.aop.functionHook(args, -1, function () {
|
|
70
|
-
TraceContextManager.resume(ctx);
|
|
71
|
-
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
self.agent.aop.before(mod.Model, hookCommand, function (obj, args) {
|
|
76
|
-
var ctx_id = TraceContextManager.getCurrentId();
|
|
77
|
-
self.agent.aop.functionHook(args, -1, function () {
|
|
78
|
-
TraceContextManager.resume(ctx_id);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
153
|
+
}).catch(e => {
|
|
154
|
+
Logger.printError("WHATAP-612", "Mongodb connection error", e, false);
|
|
155
|
+
})
|
|
156
|
+
})
|
|
81
157
|
|
|
82
158
|
};
|
|
83
159
|
|
|
@@ -5,51 +5,141 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var MeterSocketio = require('../counter/meter/meter-socket.io'),
|
|
8
|
-
|
|
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;
|
|
9
28
|
|
|
10
29
|
var SocketIOObserver = function(agent){
|
|
11
30
|
this.agent = agent;
|
|
12
31
|
this.packages = ['socket.io'];
|
|
13
32
|
};
|
|
14
33
|
|
|
15
|
-
SocketIOObserver.prototype.inject = function(
|
|
34
|
+
SocketIOObserver.prototype.inject = function (mod, moduleName) {
|
|
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
|
+
|
|
16
44
|
var self = this;
|
|
17
45
|
var aop = self.agent.aop;
|
|
18
46
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
47
|
+
aop.before(mod.Server?.prototype, 'on', function (obj, args, ret, lctx) {
|
|
48
|
+
args[args.length-1] = self.__createTransactionObserver(args[args.length-1]);
|
|
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);
|
|
24
74
|
|
|
25
|
-
|
|
26
|
-
|
|
75
|
+
var step = new SocketStep();
|
|
76
|
+
step.start_time = ctx.getElapsedTime();
|
|
77
|
+
step.ipaddr = Buffer.from(IPUtil.stringToBytes(host));
|
|
78
|
+
// step.port = port;
|
|
27
79
|
|
|
28
|
-
|
|
29
|
-
|
|
80
|
+
ctx.socket_connecting = false;
|
|
81
|
+
step.elapsed = ctx.getElapsedTime() - step.start_time;
|
|
82
|
+
ctx.profile.push(step);
|
|
30
83
|
|
|
31
|
-
|
|
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);
|
|
112
|
+
|
|
113
|
+
profile.oid = SecurityMaster.OID;
|
|
114
|
+
profile.service = wtx;
|
|
115
|
+
|
|
116
|
+
TraceContextManager.end(ctx._id);
|
|
117
|
+
setTimeout(function () {
|
|
118
|
+
DataProfileAgent.sendProfile(ctx, profile, false);
|
|
119
|
+
ctx = null;
|
|
120
|
+
}, 100);
|
|
121
|
+
|
|
122
|
+
} catch (e) {
|
|
123
|
+
Logger.printError('WHATAP-607', 'End transaction error..', e, false);
|
|
124
|
+
TraceContextManager.end(ctx._id);
|
|
125
|
+
ctx = null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
};
|
|
32
129
|
|
|
33
|
-
|
|
130
|
+
function initCtx() {
|
|
131
|
+
const ctx = TraceContextManager.start();
|
|
132
|
+
if (!ctx) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
34
135
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
136
|
+
ctx.start_malloc = ResourceProfile.getUsedHeapSize();
|
|
137
|
+
ctx.start_cpu = ResourceProfile.getCPUTime();
|
|
38
138
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
MeterSocketio.send(null, args);
|
|
42
|
-
});
|
|
139
|
+
var remote_addr = IPUtil.checkIp4("0.0.0.0");
|
|
140
|
+
ctx.remoteIp = IPUtil.stringToInt(remote_addr);
|
|
43
141
|
|
|
44
|
-
|
|
45
|
-
if (args[0] === 'disconnect') return;
|
|
46
|
-
aop.functionHook(args, -1, function (obj, args) {
|
|
47
|
-
MeterSocketio.receive(null, args[0]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
142
|
+
return ctx;
|
|
53
143
|
}
|
|
54
144
|
|
|
55
145
|
exports.SocketIOObserver = SocketIOObserver;
|
package/lib/step/method-stepx.js
CHANGED
|
@@ -29,7 +29,6 @@ MethodStepX.prototype.write = function(dout) {
|
|
|
29
29
|
dout.writeByte(0);
|
|
30
30
|
dout.writeDecimal(this.hash);
|
|
31
31
|
dout.writeDecimal(this.elapsed);
|
|
32
|
-
dout.writeByte(this.opt);
|
|
33
32
|
dout.writeDecimal(this.start_cpu);
|
|
34
33
|
dout.writeDecimal(this.start_mem);
|
|
35
34
|
dout.writeIntArray(this.stack);
|
|
@@ -39,7 +38,6 @@ MethodStepX.prototype.read = function(din) {
|
|
|
39
38
|
var ver = din.readByte();
|
|
40
39
|
this.hash = din.readDecNumber();
|
|
41
40
|
this.elapsed = din.readDecNumber();
|
|
42
|
-
this.opt = din.readByte();
|
|
43
41
|
this.start_cpu = din.readDecNumber();
|
|
44
42
|
this.start_mem = din.readDecNumber();
|
|
45
43
|
this.stack = din.readIntArray();
|
package/package.json
CHANGED
package/logs/whatap-20231212.log
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
20231212 15:46:55[WHATAP-001] <80146> Start initialize WhaTap Agent... Root[/Users/seunghunlee/workspace/nodejs_agent]
|
|
2
|
-
20231212 15:46:55[WHATAP-INIT] <80146> HttpObserver starting!
|
|
3
|
-
20231212 15:46:55[WHATAP-INIT] <80146> HttpObserver starting!
|
|
4
|
-
20231212 15:46:55[WHATAP-INIT] <80146> NetObserver starting!
|
|
5
|
-
20231212 15:46:55[WHTAP-loadObserves] <80146> unable to load mysql module
|
|
6
|
-
20231212 15:46:55[WHATAP-INIT] <80146> FileObserve starting!
|
|
7
|
-
20231212 15:46:55[WHATAP-203] <80146> Config file reloaded
|
|
8
|
-
20231212 15:46:55[WHATAP-101] <80146> Finish initialize configuration... false
|
|
9
|
-
20231212 15:46:55[WHATAP-110] <80146> [pcode=0,SECURE_KEY=]
|
|
10
|
-
20231212 15:46:55[WHATAP-170] <80146> [WhaTap Agent] now waiting for starting......
|