whatap 0.4.84 → 0.4.85
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/counter/counter-manager.js +1 -1
- package/lib/observers/http-observer.js +16 -1
- package/lib/observers/maria-observer.js +326 -348
- package/lib/observers/mssql-observer.js +5 -0
- package/lib/observers/mysql-observer.js +20 -18
- package/lib/trace/trace-context-manager.js +2 -2
- package/package.json +3 -3
|
@@ -91,7 +91,7 @@ CounterManager.prototype.process = function (tasks) {
|
|
|
91
91
|
if (ctx.getElapsedTime() > conf.profile_max_time) {
|
|
92
92
|
//TraceContextManager.end(ctx._id);
|
|
93
93
|
var obj = TraceContextManager.resume(ctx._id);
|
|
94
|
-
TraceContextManager.addStep("Lost Connection","");
|
|
94
|
+
TraceContextManager.addStep("Lost Connection","", ctx);
|
|
95
95
|
//ctx.status = 5;
|
|
96
96
|
//ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash);
|
|
97
97
|
TraceContextManager.endTrace(ctx);
|
|
@@ -46,7 +46,9 @@ var trace_origin_url = conf.getProperty('trace_origin_url', false);
|
|
|
46
46
|
var ignore_http_method = conf.getProperty('ignore_http_method', 'PATCH,OPTIONS,HEAD,TRACE');
|
|
47
47
|
var transaction_status_error_enable = conf.getProperty('transaction_status_error_enable', true);
|
|
48
48
|
var status_ignore = conf.getProperty('status_ignore', '');
|
|
49
|
+
var httpc_status_ignore = conf.getProperty('httpc_status_ignore', '');
|
|
49
50
|
var status_ignore_set = conf.getProperty('status_ignore_set', '');
|
|
51
|
+
var httpc_status_ignore_set = conf.getProperty('httpc_status_ignore_set', '');
|
|
50
52
|
var profile_error_step_enabled = conf.getProperty('profile_error_step_enabled', '');
|
|
51
53
|
conf.on('trace_http_client_ip_header_key', function(newProperty) {
|
|
52
54
|
configIpHeaderKey = newProperty;
|
|
@@ -78,9 +80,15 @@ conf.on('transaction_status_error_enable', function (newProps) {
|
|
|
78
80
|
conf.on('status_ignore', function (newProps) {
|
|
79
81
|
status_ignore = !newProps ? "" : String(newProps);
|
|
80
82
|
})
|
|
83
|
+
conf.on('httpc_status_ignore', function (newProps) {
|
|
84
|
+
httpc_status_ignore = !newProps ? "" : String(newProps);
|
|
85
|
+
})
|
|
81
86
|
conf.on('status_ignore_set', function (newProps) {
|
|
82
87
|
status_ignore_set = newProps;
|
|
83
88
|
})
|
|
89
|
+
conf.on('httpc_status_ignore_set', function (newProps) {
|
|
90
|
+
httpc_status_ignore_set = newProps;
|
|
91
|
+
})
|
|
84
92
|
conf.on('profile_error_step_enabled', function (newProps) {
|
|
85
93
|
profile_error_step_enabled = newProps;
|
|
86
94
|
})
|
|
@@ -155,7 +163,13 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
|
|
|
155
163
|
var requestPath = '';
|
|
156
164
|
if(req.route && req.route.path)
|
|
157
165
|
requestPath = req.route.path;
|
|
158
|
-
var is_ignore
|
|
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
|
+
|
|
159
173
|
if(!is_ignore)
|
|
160
174
|
self.__endTransaction(null, ctx, req, res);
|
|
161
175
|
else{
|
|
@@ -675,6 +689,7 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
|
|
|
675
689
|
})
|
|
676
690
|
ret.on('error', function(err) {
|
|
677
691
|
if (TraceContextManager.resume(ctx._id) == null) { return; }
|
|
692
|
+
ctx.is_httpc_error = true;
|
|
678
693
|
|
|
679
694
|
if (transaction_status_error_enable && step.error.isZero()) {
|
|
680
695
|
step.error = StatError.addError(err.code, err.message, ctx.service_hash,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
var TraceContextManager = require('../trace/trace-context-manager'),
|
|
8
8
|
ParsedSql = require('../trace/parsed-sql'),
|
|
9
9
|
SqlStepX = require('../step/sql-stepx'),
|
|
10
10
|
DBCStep = require('../step/dbc-step'),
|
|
@@ -26,332 +26,310 @@
|
|
|
26
26
|
MessageStep = require("../step/message-step");
|
|
27
27
|
|
|
28
28
|
var MariaObserver = function (agent) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
this.agent = agent;
|
|
30
|
+
this.packages = ['mariadb'];
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
var queryHook = function (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
33
|
+
var queryHook = function (dbc, agent) {
|
|
34
|
+
|
|
35
|
+
return function (obj, args) {
|
|
36
|
+
var ctx = TraceContextManager.getCurrentContext();
|
|
37
|
+
|
|
38
|
+
if (ctx == null || args[0] == null) { return; }
|
|
39
|
+
if(args[0].sql == null && typeof args[0] != 'string') { return; }
|
|
40
|
+
|
|
41
|
+
var dbc_step = new DBCStep();
|
|
42
|
+
var dbc_hash = HashUtil.hashFromString(dbc);
|
|
43
|
+
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
44
|
+
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
45
|
+
DataTextAgent.ERROR.add(dbc_hash, dbc)
|
|
46
|
+
|
|
47
|
+
dbc_step.hash = dbc_hash;
|
|
48
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
49
|
+
ctx.profile.push(dbc_step);
|
|
50
|
+
|
|
51
|
+
var sql_step = new SqlStepX();
|
|
52
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
53
|
+
ctx.profile.push(sql_step);
|
|
54
|
+
|
|
55
|
+
ctx.footprint('Maria Query Start');
|
|
56
|
+
|
|
57
|
+
ctx.sql_count++;
|
|
58
|
+
|
|
59
|
+
var sql = args.length > 0 ? args[0] : undefined,
|
|
60
|
+
psql = null;
|
|
61
|
+
|
|
62
|
+
if(typeof sql !== 'string') {
|
|
63
|
+
sql = args[0].sql || undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (typeof sql === 'string' && sql.length > 0) {
|
|
67
|
+
try {
|
|
68
|
+
psql = escapeLiteral(sql);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
Logger.printError('WHATAP-191', 'MariaObserver escapeliteral error', e);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
sql = '';
|
|
74
|
+
psql = escapeLiteral(sql);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if(psql != null) {
|
|
78
|
+
sql_step.hash = psql.sql;
|
|
79
|
+
// sql_step.crud = psql.type.charCodeAt(0);
|
|
80
|
+
}
|
|
81
|
+
sql_step.dbc = dbc_hash;
|
|
82
|
+
|
|
83
|
+
var els = new EscapeLiteralSQL(sql);
|
|
84
|
+
els.process();
|
|
85
|
+
|
|
86
|
+
ctx.active_sqlhash = sql_step.hash;
|
|
87
|
+
ctx.active_dbc = sql_step.dbc;
|
|
88
|
+
//ctx.active_crud = sql_step.crud;
|
|
89
|
+
|
|
90
|
+
if(conf.profile_sql_param_enabled) {
|
|
91
|
+
var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
|
|
92
|
+
sql_step.setTrue(1);
|
|
93
|
+
var crc = {value : 0};
|
|
94
|
+
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
95
|
+
if(params != undefined) {
|
|
96
|
+
const result = params.map((param) => {
|
|
97
|
+
if(typeof param === 'string'){
|
|
98
|
+
return `'${param}'`
|
|
99
|
+
}
|
|
100
|
+
return param
|
|
101
|
+
}).toString()
|
|
102
|
+
sql_step.p2 = toParamBytes(result, crc);
|
|
103
|
+
}
|
|
104
|
+
sql_step.pcrc = crc.value;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var lastCallback = false;
|
|
108
|
+
|
|
109
|
+
function queryCallback(obj, args) {
|
|
110
|
+
if (ctx == null) { return; }
|
|
111
|
+
TraceContextManager.resume(ctx._id);
|
|
112
|
+
|
|
113
|
+
if(args[0]) {
|
|
114
|
+
try{
|
|
115
|
+
if (conf.trace_sql_error_stack && conf.trace_sql_error_depth) {
|
|
116
|
+
var traceDepth = conf.trace_sql_error_depth;
|
|
117
|
+
|
|
118
|
+
var errorStack = args[0].stack.split("\n");
|
|
119
|
+
if (errorStack.length > traceDepth) {
|
|
120
|
+
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
121
|
+
}
|
|
122
|
+
var errorStackString = errorStack.join("\n");
|
|
123
|
+
var error_stack_step = new MessageStep();
|
|
124
|
+
error_stack_step.hash = HashUtil.hashFromString("ERROR STACK");
|
|
125
|
+
error_stack_step.start_time = ctx.getElapsedTime();
|
|
126
|
+
error_stack_step.desc = errorStackString;
|
|
127
|
+
DataTextAgent.MESSAGE.add(error_stack_step.hash, "ERROR STACK");
|
|
128
|
+
ctx.profile.push(error_stack_step);
|
|
129
|
+
}
|
|
130
|
+
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
131
|
+
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
132
|
+
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
133
|
+
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
134
|
+
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
135
|
+
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
136
|
+
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
137
|
+
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
138
|
+
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
139
|
+
}
|
|
140
|
+
}catch(e) {
|
|
141
|
+
|
|
129
142
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
agent.aop.both(args[0], '_callback', queryCallback);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
146
|
+
ctx.sql_time += sql_step.elapsed;
|
|
147
|
+
|
|
148
|
+
ctx.footprint('Maria Query Done');
|
|
149
|
+
|
|
150
|
+
MeterSql.add(dbc_hash, sql_step.elapsed, false);
|
|
151
|
+
StatSql.addSqlTime( ctx.service_hash, sql_step.dbc,
|
|
152
|
+
sql_step.hash, sql_step.elapsed, args[0] != null, 0);
|
|
153
|
+
|
|
154
|
+
if (Array.isArray(args[1]) && psql != null && psql.type === 'S') {
|
|
155
|
+
var result_step = new ResultSetStep();
|
|
156
|
+
result_step.start_time = ctx.getElapsedTime();
|
|
157
|
+
result_step.elapsed = 0;
|
|
158
|
+
result_step.fetch = args[1].length;
|
|
159
|
+
result_step.sqlhash = psql.sql;
|
|
160
|
+
result_step.dbc = dbc_hash;
|
|
161
|
+
ctx.profile.push(result_step);
|
|
162
|
+
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
|
|
163
|
+
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (args[1] != null && psql != null && psql.type === 'U') {
|
|
167
|
+
sql_step.updated = args[1].affectedRows || 0;
|
|
168
|
+
//StatSql.addUpdate(dbc_hash, psql.sql, sql_step.updated);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
lastCallback = agent.aop.functionHook(args, -1, queryCallback);
|
|
173
|
+
|
|
174
|
+
if(lastCallback === false && args.length>0 && args[0]._callback){
|
|
175
|
+
agent.aop.both(args[0], '_callback', queryCallback);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
168
178
|
};
|
|
169
179
|
|
|
170
180
|
var toParamBytes = function(p, crc) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
if(p == null || p.length === 0) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
try{
|
|
185
|
+
return ParamSecurity.encrypt(Buffer.from(p), crc);
|
|
186
|
+
} catch(e) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
179
189
|
};
|
|
180
190
|
|
|
181
191
|
var errorDelegate = function () {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
200
|
-
} else {
|
|
201
|
-
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
202
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
203
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
204
|
-
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
205
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
206
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
207
|
-
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
208
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
192
|
+
return function (obj, args) {
|
|
193
|
+
var ctx = TraceContextManager.getCurrentContext();
|
|
194
|
+
if(ctx == null) { return; }
|
|
195
|
+
|
|
196
|
+
var laststep = ctx.profile.getLastSteps(1);
|
|
197
|
+
if(laststep == null || laststep.length === 0) { return; }
|
|
198
|
+
|
|
199
|
+
var step = laststep[0];
|
|
200
|
+
if(!args[0].fatal) {
|
|
201
|
+
MeterSql.add(step.dbc, step.elapsed, true);
|
|
202
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, step.dbc, step.hash, step.elapsed, true, 0);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
try{
|
|
206
|
+
if(args[0].fatal) {
|
|
207
|
+
// Connection Error
|
|
208
|
+
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message, ctx.service_hash); /*long*/
|
|
209
209
|
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
210
|
+
} else {
|
|
211
|
+
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
212
|
+
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
213
|
+
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
214
|
+
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
215
|
+
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
216
|
+
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
217
|
+
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
218
|
+
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
219
|
+
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
220
|
+
}
|
|
210
221
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
222
|
+
} catch(e) {
|
|
223
|
+
}
|
|
224
|
+
}
|
|
215
225
|
};
|
|
216
226
|
|
|
217
227
|
MariaObserver.prototype.inject = function (mod, moduleName) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
dbc_pool_hash = HashUtil.hashFromString(dbc);
|
|
324
|
-
DataTextAgent.DBC.add(dbc_pool_hash, dbc);
|
|
325
|
-
DataTextAgent.METHOD.add(dbc_pool_hash, dbc);
|
|
326
|
-
DataTextAgent.ERROR.add(dbc_pool_hash, dbc);
|
|
327
|
-
}
|
|
328
|
-
aop.both(ret, 'getConnection', function (obj, args, lctx) {
|
|
329
|
-
var ctx = TraceContextManager.getCurrentContext();
|
|
330
|
-
if(ctx == null) {return;}
|
|
331
|
-
|
|
332
|
-
var dbc_step = new DBCStep();
|
|
333
|
-
dbc_step.hash = dbc_pool_hash;
|
|
334
|
-
dbc_step.start_time = ctx.getElapsedTime();
|
|
335
|
-
|
|
336
|
-
aop.functionHook(args, -1, function (obj, args) {
|
|
337
|
-
dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
338
|
-
ctx.profile.push(dbc_step);
|
|
339
|
-
|
|
340
|
-
TraceContextManager.resume(ctx._id);
|
|
341
|
-
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
342
|
-
|
|
343
|
-
if(args[0] != null) { return; }
|
|
344
|
-
var conn = args[1];
|
|
345
|
-
if(conn.__query_hook__) { return; }
|
|
346
|
-
conn.__query_hook__ = true;
|
|
347
|
-
aop.before(conn, 'query', queryHook(dbc_pool_hash, self.agent));
|
|
348
|
-
aop.before(conn, 'execute', queryHook(dbc_pool_hash, self.agent));
|
|
349
|
-
aop.before(conn._protocol, '_delegateError', errorDelegate(ctx));
|
|
350
|
-
});
|
|
351
|
-
}, function (obj, args, ret, lctx) {
|
|
352
|
-
MeterSql.setConnection(1, 0, dbc);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
228
|
+
if (mod.__whatap_observe__) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
mod.__whatap_observe__ = true;
|
|
232
|
+
Logger.initPrint("MariaObserver");
|
|
233
|
+
var self = this;
|
|
234
|
+
var aop = self.agent.aop;
|
|
235
|
+
|
|
236
|
+
if (conf.sql_enabled === false) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var dbc_hash = 0;
|
|
241
|
+
var dbc = 'maria://';
|
|
242
|
+
aop.both(mod, 'createConnection',
|
|
243
|
+
function (obj, args, lctx) {
|
|
244
|
+
var ctx = lctx.context;
|
|
245
|
+
if (ctx == null || ctx.db_opening) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
ctx.db_opening = true;
|
|
249
|
+
ctx.footprint('Maria Connecting Start');
|
|
250
|
+
|
|
251
|
+
var dbc_step = new DBCStep();
|
|
252
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
253
|
+
lctx.step = dbc_step;
|
|
254
|
+
},
|
|
255
|
+
function (obj, args, ret, lctx) {
|
|
256
|
+
if (dbc_hash === 0) {
|
|
257
|
+
if (args.length > 0) {
|
|
258
|
+
var info = (args[0] || {});
|
|
259
|
+
dbc = 'maria://';
|
|
260
|
+
dbc += info.user || '';
|
|
261
|
+
dbc += "@";
|
|
262
|
+
dbc += info.host || '';
|
|
263
|
+
dbc += '/';
|
|
264
|
+
dbc += info.database || '';
|
|
265
|
+
dbc_hash = HashUtil.hashFromString(dbc);
|
|
266
|
+
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
267
|
+
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
268
|
+
DataTextAgent.ERROR.add(dbc_hash, dbc);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
ret.then(connection => {
|
|
273
|
+
aop.both(connection, 'query', queryHook(dbc, self.agent), function (_obj, _args, _ret, _lctx) {
|
|
274
|
+
var ctx = _lctx.context;
|
|
275
|
+
TraceContextManager.resume(ctx);
|
|
276
|
+
});
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
ret.then(connection => {
|
|
280
|
+
aop.both(connection, 'execute', queryHook(dbc, self.agent), function (_obj, _args, _ret, _lctx) {
|
|
281
|
+
var ctx = _lctx.context;
|
|
282
|
+
TraceContextManager.resume(ctx);
|
|
283
|
+
});
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
// aop.both(ret, 'execute', queryHook(dbc, self.agent), function (obj, args, ret, lctx) {
|
|
287
|
+
// var ctx = lctx.context;
|
|
288
|
+
// TraceContextManager.resume(ctx);
|
|
289
|
+
// });
|
|
290
|
+
//
|
|
291
|
+
// aop.after(ret._protocol, '_delegateError', errorDelegate());
|
|
292
|
+
|
|
293
|
+
var ctx = lctx.context,
|
|
294
|
+
step = lctx.step;
|
|
295
|
+
|
|
296
|
+
if (ctx == null || step == null) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
TraceContextManager.resume(ctx);
|
|
301
|
+
ctx.footprint('Maria Connecting Done');
|
|
302
|
+
ctx.db_opening = false;
|
|
303
|
+
step.hash = dbc_hash;
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
var dbc_pool_hash = 0;
|
|
308
|
+
aop.after(mod, ['createPool', 'createPoolCluster'], function (obj, args, ret) {
|
|
309
|
+
if (dbc_pool_hash == 0) {
|
|
310
|
+
if (args.length > 0) {
|
|
311
|
+
var info = args[0];
|
|
312
|
+
dbc += info.user || '';
|
|
313
|
+
dbc += "@";
|
|
314
|
+
dbc += info.host || '';
|
|
315
|
+
dbc += '/';
|
|
316
|
+
dbc += info.database || '';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
aop.after(ret, 'getConnection', function (_obj, _args, _ret, _lctx) {
|
|
321
|
+
_ret.then(connection => {
|
|
322
|
+
aop.both(connection, 'query', queryHook(dbc, self.agent), function (__obj, __args, __ret, __lctx) {
|
|
323
|
+
var ctx = __lctx.context;
|
|
324
|
+
TraceContextManager.resume(ctx);
|
|
325
|
+
});
|
|
326
|
+
aop.both(connection, 'execute', queryHook(dbc, self.agent), function (__obj, __args, __ret, __lctx) {
|
|
327
|
+
var ctx = __lctx.context;
|
|
328
|
+
TraceContextManager.resume(ctx);
|
|
329
|
+
});
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
});
|
|
355
333
|
};
|
|
356
334
|
|
|
357
335
|
var checkedSql = new IntKeyMap(2000).setMax(2000);
|
|
@@ -359,41 +337,41 @@ var nonLiteSql = new IntKeyMap(5000).setMax(5000);
|
|
|
359
337
|
var date = DateUtil.yyyymmdd();
|
|
360
338
|
|
|
361
339
|
function escapeLiteral(sql) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
340
|
+
if(sql == null) { sql = ''; }
|
|
341
|
+
|
|
342
|
+
if(date !== DateUtil.yyyymmdd()) {
|
|
343
|
+
checkedSql.clear();
|
|
344
|
+
nonLiteSql.clear();
|
|
345
|
+
date = DateUtil.yyyymmdd();
|
|
346
|
+
Logger.print('WHATAP-SQL-CLEAR', 'MariaObserver CLEAR OK!!!!!!!!!!!!!!!!', false);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
var sqlHash = HashUtil.hashFromString(sql);
|
|
350
|
+
var psql = nonLiteSql.get(sqlHash);
|
|
351
|
+
|
|
352
|
+
if(psql != null) {
|
|
353
|
+
return psql;
|
|
354
|
+
}
|
|
355
|
+
psql = checkedSql.get(sqlHash);
|
|
356
|
+
|
|
357
|
+
if(psql != null) {
|
|
358
|
+
return psql;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
var els = new EscapeLiteralSQL(sql);
|
|
362
|
+
els.process();
|
|
363
|
+
|
|
364
|
+
var hash = HashUtil.hashFromString(els.getParsedSql());
|
|
365
|
+
DataTextAgent.SQL.add(hash, els.getParsedSql());
|
|
366
|
+
|
|
367
|
+
if(hash === sqlHash) {
|
|
368
|
+
psql = new ParsedSql(els.sqlType, hash, null);
|
|
369
|
+
nonLiteSql.put(sqlHash, psql);
|
|
370
|
+
} else {
|
|
371
|
+
psql = new ParsedSql(els.sqlType, hash, els.getParameter());
|
|
372
|
+
checkedSql.put(sqlHash, psql);
|
|
373
|
+
}
|
|
374
|
+
return psql;
|
|
397
375
|
}
|
|
398
376
|
|
|
399
377
|
exports.MariaObserver = MariaObserver;
|
|
@@ -70,6 +70,11 @@ MssqlObserver.prototype.inject = function (mod, modName) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
var dbc_step = new DBCStep();
|
|
74
|
+
dbc_step.hash = dbc_hash;
|
|
75
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
76
|
+
ctx.profile.push(dbc_step);
|
|
77
|
+
|
|
73
78
|
sql_step.dbc = dbc_hash;
|
|
74
79
|
|
|
75
80
|
try {
|
|
@@ -30,7 +30,7 @@ var MysqlObserver = function (agent) {
|
|
|
30
30
|
this.packages = ['mysql', 'mysql2'];
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
var queryHook = function (
|
|
33
|
+
var queryHook = function (dbc, agent) {
|
|
34
34
|
|
|
35
35
|
return function (obj, args) {
|
|
36
36
|
var ctx = TraceContextManager.getCurrentContext();
|
|
@@ -42,6 +42,16 @@ var queryHook = function (dbc_hash, agent) {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
var dbc_step = new DBCStep();
|
|
46
|
+
var dbc_hash = HashUtil.hashFromString(dbc);
|
|
47
|
+
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
48
|
+
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
49
|
+
DataTextAgent.ERROR.add(dbc_hash, dbc)
|
|
50
|
+
|
|
51
|
+
dbc_step.hash = dbc_hash;
|
|
52
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
53
|
+
ctx.profile.push(dbc_step);
|
|
54
|
+
|
|
45
55
|
var sql_step = new SqlStepX();
|
|
46
56
|
sql_step.start_time = ctx.getElapsedTime();
|
|
47
57
|
ctx.profile.push(sql_step);
|
|
@@ -261,6 +271,7 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
261
271
|
}
|
|
262
272
|
|
|
263
273
|
var dbc_hash = 0;
|
|
274
|
+
var dbc = 'mysql://';
|
|
264
275
|
aop.both(mod, 'createConnection',
|
|
265
276
|
function (obj, args, lctx) {
|
|
266
277
|
var ctx = lctx.context;
|
|
@@ -277,7 +288,6 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
277
288
|
function (obj, args, ret, lctx) {
|
|
278
289
|
|
|
279
290
|
if (dbc_hash === 0) {
|
|
280
|
-
var dbc;
|
|
281
291
|
if (args.length > 0) {
|
|
282
292
|
var info = (args[0] || {});
|
|
283
293
|
dbc = 'mysql://';
|
|
@@ -293,12 +303,12 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
293
303
|
}
|
|
294
304
|
}
|
|
295
305
|
|
|
296
|
-
aop.both(ret, 'query', queryHook(
|
|
306
|
+
aop.both(ret, 'query', queryHook(dbc, self.agent), function (obj, args, ret, lctx) {
|
|
297
307
|
var ctx = lctx.context;
|
|
298
308
|
TraceContextManager.resume(ctx);
|
|
299
309
|
});
|
|
300
310
|
|
|
301
|
-
aop.both(ret, 'execute', queryHook(
|
|
311
|
+
aop.both(ret, 'execute', queryHook(dbc, self.agent), function (obj, args, ret, lctx) {
|
|
302
312
|
var ctx = lctx.context;
|
|
303
313
|
TraceContextManager.resume(ctx);
|
|
304
314
|
});
|
|
@@ -350,7 +360,6 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
350
360
|
|
|
351
361
|
var dbc_pool_hash = 0;
|
|
352
362
|
aop.after(mod, ['createPool', 'createPoolCluster'], function (obj, args, ret) {
|
|
353
|
-
var dbc = 'mysql://';
|
|
354
363
|
if (dbc_pool_hash == 0) {
|
|
355
364
|
if (args.length > 0) {
|
|
356
365
|
var info = args[0];
|
|
@@ -362,10 +371,10 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
362
371
|
dbc += info.database || '';
|
|
363
372
|
}
|
|
364
373
|
|
|
365
|
-
dbc_pool_hash = HashUtil.hashFromString(dbc);
|
|
366
|
-
DataTextAgent.DBC.add(dbc_pool_hash, dbc);
|
|
367
|
-
DataTextAgent.METHOD.add(dbc_pool_hash, dbc);
|
|
368
|
-
DataTextAgent.ERROR.add(dbc_pool_hash, dbc);
|
|
374
|
+
// dbc_pool_hash = HashUtil.hashFromString(dbc);
|
|
375
|
+
// DataTextAgent.DBC.add(dbc_pool_hash, dbc);
|
|
376
|
+
// DataTextAgent.METHOD.add(dbc_pool_hash, dbc);
|
|
377
|
+
// DataTextAgent.ERROR.add(dbc_pool_hash, dbc);
|
|
369
378
|
}
|
|
370
379
|
aop.both(ret, 'getConnection', function (obj, args, lctx) {
|
|
371
380
|
var ctx = TraceContextManager.getCurrentContext();
|
|
@@ -373,14 +382,7 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
373
382
|
return;
|
|
374
383
|
}
|
|
375
384
|
|
|
376
|
-
var dbc_step = new DBCStep();
|
|
377
|
-
dbc_step.hash = dbc_pool_hash;
|
|
378
|
-
dbc_step.start_time = ctx.getElapsedTime();
|
|
379
|
-
|
|
380
385
|
aop.functionHook(args, -1, function (obj, args) {
|
|
381
|
-
dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
382
|
-
ctx.profile.push(dbc_step);
|
|
383
|
-
|
|
384
386
|
TraceContextManager.resume(ctx._id);
|
|
385
387
|
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
386
388
|
|
|
@@ -392,8 +394,8 @@ MysqlObserver.prototype.inject = function (mod, moduleName) {
|
|
|
392
394
|
return;
|
|
393
395
|
}
|
|
394
396
|
conn.__query_hook__ = true;
|
|
395
|
-
aop.before(conn, 'query', queryHook(
|
|
396
|
-
aop.before(conn, 'execute', queryHook(
|
|
397
|
+
aop.before(conn, 'query', queryHook(dbc, self.agent));
|
|
398
|
+
aop.before(conn, 'execute', queryHook(dbc, self.agent));
|
|
397
399
|
aop.before(conn._protocol, '_delegateError', errorDelegate(ctx));
|
|
398
400
|
});
|
|
399
401
|
}, function (obj, args, ret, lctx) {
|
|
@@ -99,8 +99,8 @@ TraceContextManager.prototype.isExist = function (id) {
|
|
|
99
99
|
};
|
|
100
100
|
var DataTextAgent = require('../data/datatext-agent');
|
|
101
101
|
var MessageStep = require('../step/message-step');
|
|
102
|
-
TraceContextManager.prototype.addStep = function (title, desc) {
|
|
103
|
-
var ctx = this.getCurrentContext();
|
|
102
|
+
TraceContextManager.prototype.addStep = function (title, desc, ctx) {
|
|
103
|
+
// var ctx = this.getCurrentContext();
|
|
104
104
|
if(ctx == null) {
|
|
105
105
|
return null;
|
|
106
106
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whatap",
|
|
3
3
|
"homepage": "http://www.whatap.io",
|
|
4
|
-
"version": "0.4.
|
|
5
|
-
"releaseDate": "
|
|
4
|
+
"version": "0.4.85",
|
|
5
|
+
"releaseDate": "20240104",
|
|
6
6
|
"description": "Monitoring and Profiling Service",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "UNLICENSED",
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=v16.4.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"crypto": "^1.0.1",
|