whatap 0.5.1 → 0.5.3
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/counter/counter-manager.js +12 -7
- package/lib/observers/http-observer.js +115 -143
- package/lib/observers/maria-observer.js +180 -271
- package/lib/observers/mssql-observer.js +11 -17
- package/lib/observers/mysql-observer.js +10 -12
- package/lib/observers/pgsql-observer.js +192 -212
- package/lib/trace/trace-httpc.js +26 -0
- package/lib/trace/trace-sql.js +45 -0
- package/package.json +2 -2
|
@@ -23,321 +23,230 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
23
23
|
conf = require('../conf/configure'),
|
|
24
24
|
DateUtil = require('../util/dateutil'),
|
|
25
25
|
Buffer = require('buffer').Buffer,
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
shimmer = require('../core/shimmer'),
|
|
27
|
+
TraceSQL = require('../trace/trace-sql');
|
|
28
28
|
|
|
29
29
|
var MariaObserver = function (agent) {
|
|
30
30
|
this.agent = agent;
|
|
31
31
|
this.packages = ['mariadb'];
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
var dbc, dbc_hash;
|
|
35
|
+
MariaObserver.prototype.inject = function (mod, moduleName) {
|
|
36
|
+
if (mod.__whatap_observe__) { return; }
|
|
37
|
+
mod.__whatap_observe__ = true;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
if(args[0].sql == null && typeof args[0] != 'string') { return; }
|
|
39
|
+
Logger.initPrint("MariaObserver");
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
var dbc_hash = HashUtil.hashFromString(dbc);
|
|
44
|
-
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
45
|
-
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
46
|
-
DataTextAgent.ERROR.add(dbc_hash, dbc)
|
|
41
|
+
if (!conf.sql_enabled) return;
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
// shimmer.wrap(mod, 'createConnection', wrapCreateConnection(mod));
|
|
44
|
+
shimmer.wrap(mod, 'createConnection', wrapConnection(mod));
|
|
45
|
+
shimmer.wrap(mod, 'createPool', wrapCreatePool(mod));
|
|
46
|
+
};
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
var _finishQuery = function (ctx, sql_step) {
|
|
49
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
50
|
+
TraceSQL.isSlowSQL(ctx);
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
53
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, false, 0);
|
|
54
|
+
};
|
|
57
55
|
|
|
58
|
-
|
|
56
|
+
var _handleError = function (ctx, sql_step, err) {
|
|
57
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
58
|
+
TraceSQL.isSlowSQL(ctx);
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
61
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0);
|
|
62
|
+
};
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
function wrapCreateConnection(agent) {
|
|
65
|
+
return function (original) {
|
|
66
|
+
return async function (...args) {
|
|
67
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
68
|
+
if (!ctx || ctx.db_opening) return original.apply(this, args);
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
psql = escapeLiteral(sql);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
Logger.printError('WHATAP-191', 'MariaObserver escapeliteral error', e);
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
sql = '';
|
|
75
|
-
psql = escapeLiteral(sql);
|
|
76
|
-
}
|
|
70
|
+
ctx.db_opening = true;
|
|
71
|
+
ctx.footprint('Maria Connecting Start');
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// sql_step.crud = psql.type.charCodeAt(0);
|
|
81
|
-
}
|
|
82
|
-
sql_step.dbc = dbc_hash;
|
|
83
|
-
|
|
84
|
-
var els = new EscapeLiteralSQL(sql);
|
|
85
|
-
els.process();
|
|
86
|
-
|
|
87
|
-
ctx.active_sqlhash = sql_step.hash;
|
|
88
|
-
ctx.active_dbc = sql_step.dbc;
|
|
89
|
-
//ctx.active_crud = sql_step.crud;
|
|
90
|
-
|
|
91
|
-
if(conf.profile_sql_param_enabled) {
|
|
92
|
-
var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
|
|
93
|
-
sql_step.setTrue(1);
|
|
94
|
-
var crc = {value : 0};
|
|
95
|
-
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
96
|
-
if(params != undefined) {
|
|
97
|
-
const result = params.map((param) => {
|
|
98
|
-
if(typeof param === 'string'){
|
|
99
|
-
return `'${param}'`
|
|
100
|
-
}
|
|
101
|
-
return param
|
|
102
|
-
}).toString()
|
|
103
|
-
sql_step.p2 = toParamBytes(result, crc);
|
|
104
|
-
}
|
|
105
|
-
sql_step.pcrc = crc.value;
|
|
106
|
-
}
|
|
73
|
+
// const dbc_step = new DBCStep();
|
|
74
|
+
// dbc_step.start_time = ctx.getElapsedTime();
|
|
107
75
|
|
|
108
|
-
|
|
76
|
+
const connection = await original.apply(this, args);
|
|
77
|
+
wrapConnectionMethods(connection, agent);
|
|
109
78
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
TraceContextManager.resume(ctx._id);
|
|
79
|
+
ctx.footprint('Maria Connecting Done');
|
|
80
|
+
ctx.db_opening = false;
|
|
113
81
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var traceDepth = conf.trace_sql_error_depth;
|
|
82
|
+
getDBCHash(args);
|
|
83
|
+
// dbc_step.hash = dbc_hash;
|
|
84
|
+
// ctx.profile.push(dbc_step);
|
|
118
85
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var errorStackString = errorStack.join("\n");
|
|
124
|
-
var error_stack_step = new MessageStep();
|
|
125
|
-
error_stack_step.hash = HashUtil.hashFromString("ERROR STACK");
|
|
126
|
-
error_stack_step.start_time = ctx.getElapsedTime();
|
|
127
|
-
error_stack_step.desc = errorStackString;
|
|
128
|
-
DataTextAgent.MESSAGE.add(error_stack_step.hash, "ERROR STACK");
|
|
129
|
-
ctx.profile.push(error_stack_step);
|
|
130
|
-
}
|
|
131
|
-
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
132
|
-
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
133
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
134
|
-
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
135
|
-
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
136
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
137
|
-
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
138
|
-
sql_step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
139
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
140
|
-
}
|
|
141
|
-
}catch(e) {
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
86
|
+
return connection;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
145
90
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// sql_step.start_mem = ResourceProfile.getUsedHeapSize();
|
|
152
|
-
// }
|
|
153
|
-
|
|
154
|
-
ctx.footprint('Maria Query Done');
|
|
155
|
-
|
|
156
|
-
MeterSql.add(dbc_hash, sql_step.elapsed, false);
|
|
157
|
-
StatSql.addSqlTime( ctx.service_hash, sql_step.dbc,
|
|
158
|
-
sql_step.hash, sql_step.elapsed, args[0] != null, 0);
|
|
159
|
-
|
|
160
|
-
if (Array.isArray(args[1]) && psql != null && psql.type === 'S') {
|
|
161
|
-
var result_step = new ResultSetStep();
|
|
162
|
-
result_step.start_time = ctx.getElapsedTime();
|
|
163
|
-
result_step.elapsed = 0;
|
|
164
|
-
result_step.fetch = args[1].length;
|
|
165
|
-
result_step.sqlhash = psql.sql;
|
|
166
|
-
result_step.dbc = dbc_hash;
|
|
167
|
-
ctx.profile.push(result_step);
|
|
168
|
-
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
|
|
169
|
-
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
|
|
170
|
-
}
|
|
91
|
+
function wrapConnection(agent) {
|
|
92
|
+
return function (original) {
|
|
93
|
+
return function (...args) {
|
|
94
|
+
const connectionPromise = original.apply(this, args);
|
|
95
|
+
getDBCHash(args);
|
|
171
96
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
97
|
+
return connectionPromise.then(connection => {
|
|
98
|
+
shimmer.wrap(connection, 'query', createQueryHook(agent));
|
|
99
|
+
return connection;
|
|
100
|
+
});
|
|
176
101
|
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
177
104
|
|
|
178
|
-
|
|
105
|
+
function wrapCreatePool(agent) {
|
|
106
|
+
return function (original) {
|
|
107
|
+
return function (...args) {
|
|
108
|
+
const pool = original.apply(this, args);
|
|
109
|
+
getDBCHash(args);
|
|
110
|
+
|
|
111
|
+
shimmer.wrap(pool, 'getConnection', (originalGetConnection) => {
|
|
112
|
+
return async function (...connArgs) {
|
|
113
|
+
const connection = await originalGetConnection.apply(this, connArgs);
|
|
114
|
+
wrapConnectionMethods(connection, agent);
|
|
115
|
+
return connection;
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return pool;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
}
|
|
179
123
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
124
|
+
function wrapConnectionMethods(connection, agent) {
|
|
125
|
+
shimmer.wrap(connection, 'query', createQueryHook(agent));
|
|
126
|
+
shimmer.wrap(connection, 'execute', createQueryHook(agent));
|
|
127
|
+
}
|
|
185
128
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return ParamSecurity.encrypt(Buffer.from(p), crc);
|
|
192
|
-
} catch(e) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
129
|
+
function createQueryHook(agent) {
|
|
130
|
+
return function (original) {
|
|
131
|
+
return function (...args) {
|
|
132
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
133
|
+
if (!ctx || !args[0]) return original.apply(this, args);
|
|
196
134
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
var ctx = TraceContextManager.getCurrentContext();
|
|
200
|
-
if(ctx == null) { return; }
|
|
135
|
+
ctx.db_opening = true;
|
|
136
|
+
ctx.footprint('Maria Connecting Start');
|
|
201
137
|
|
|
202
|
-
|
|
203
|
-
|
|
138
|
+
const dbc_step = new DBCStep();
|
|
139
|
+
ctx.footprint('Maria Connecting Done');
|
|
140
|
+
ctx.db_opening = false;
|
|
204
141
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
MeterSql.add(step.dbc, step.elapsed, true);
|
|
208
|
-
StatSql.addSqlTime(ctx, ctx.service_hash, step.dbc, step.hash, step.elapsed, true, 0);
|
|
209
|
-
}
|
|
142
|
+
dbc_step.hash = dbc_hash;
|
|
143
|
+
ctx.profile.push(dbc_step);
|
|
210
144
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message, ctx.service_hash); /*long*/
|
|
215
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
216
|
-
} else {
|
|
217
|
-
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
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
|
-
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
221
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
222
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
223
|
-
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
224
|
-
step.error = StatError.addError( 'Maria-'+args[0].code, args[0].message || 'Maria error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
225
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
} catch(e) {
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
};
|
|
145
|
+
const sql_step = new SqlStepX();
|
|
146
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
147
|
+
ctx.profile.push(sql_step);
|
|
232
148
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
mod.__whatap_observe__ = true;
|
|
238
|
-
Logger.initPrint("MariaObserver");
|
|
239
|
-
var self = this;
|
|
240
|
-
var aop = self.agent.aop;
|
|
149
|
+
ctx.footprint('Maria Query Start');
|
|
150
|
+
ctx.sql_count++;
|
|
241
151
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
152
|
+
var sql = args.length > 0 ? args[0] : undefined,
|
|
153
|
+
psql = null;
|
|
245
154
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
aop.both(mod, 'createConnection',
|
|
249
|
-
function (obj, args, lctx) {
|
|
250
|
-
var ctx = lctx.context;
|
|
251
|
-
if (ctx == null || ctx.db_opening) {
|
|
252
|
-
return;
|
|
155
|
+
if(typeof sql !== 'string') {
|
|
156
|
+
sql = args[0].sql || undefined;
|
|
253
157
|
}
|
|
254
|
-
ctx.db_opening = true;
|
|
255
|
-
ctx.footprint('Maria Connecting Start');
|
|
256
158
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (dbc_hash === 0) {
|
|
263
|
-
if (args.length > 0) {
|
|
264
|
-
var info = (args[0] || {});
|
|
265
|
-
dbc = 'maria://';
|
|
266
|
-
dbc += info.user || '';
|
|
267
|
-
dbc += "@";
|
|
268
|
-
dbc += info.host || '';
|
|
269
|
-
dbc += '/';
|
|
270
|
-
dbc += info.database || '';
|
|
271
|
-
dbc_hash = HashUtil.hashFromString(dbc);
|
|
272
|
-
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
273
|
-
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
274
|
-
DataTextAgent.ERROR.add(dbc_hash, dbc);
|
|
159
|
+
if (typeof sql === 'string' && sql.length > 0) {
|
|
160
|
+
try {
|
|
161
|
+
psql = escapeLiteral(sql);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
Logger.printError('WHATAP-191', 'MariaObserver escapeliteral error', e);
|
|
275
164
|
}
|
|
165
|
+
} else {
|
|
166
|
+
sql = '';
|
|
167
|
+
psql = escapeLiteral(sql);
|
|
276
168
|
}
|
|
277
169
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
TraceContextManager.resume(ctx);
|
|
282
|
-
});
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
ret.then(connection => {
|
|
286
|
-
aop.both(connection, 'execute', queryHook(dbc, self.agent), function (_obj, _args, _ret, _lctx) {
|
|
287
|
-
var ctx = _lctx.context;
|
|
288
|
-
TraceContextManager.resume(ctx);
|
|
289
|
-
});
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
// aop.both(ret, 'execute', queryHook(dbc, self.agent), function (obj, args, ret, lctx) {
|
|
293
|
-
// var ctx = lctx.context;
|
|
294
|
-
// TraceContextManager.resume(ctx);
|
|
295
|
-
// });
|
|
296
|
-
//
|
|
297
|
-
// aop.after(ret._protocol, '_delegateError', errorDelegate());
|
|
298
|
-
|
|
299
|
-
var ctx = lctx.context,
|
|
300
|
-
step = lctx.step;
|
|
301
|
-
|
|
302
|
-
if (ctx == null || step == null) {
|
|
303
|
-
return;
|
|
170
|
+
if(psql != null) {
|
|
171
|
+
sql_step.hash = psql.sql;
|
|
172
|
+
// sql_step.crud = psql.type.charCodeAt(0);
|
|
304
173
|
}
|
|
305
174
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
175
|
+
var els = new EscapeLiteralSQL(sql);
|
|
176
|
+
els.process();
|
|
177
|
+
|
|
178
|
+
ctx.active_sqlhash = sql_step.hash;
|
|
179
|
+
|
|
180
|
+
if(conf.profile_sql_param_enabled) {
|
|
181
|
+
var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
|
|
182
|
+
sql_step.setTrue(1);
|
|
183
|
+
var crc = {value : 0};
|
|
184
|
+
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
185
|
+
if(params != undefined) {
|
|
186
|
+
const result = params.map((param) => {
|
|
187
|
+
if(typeof param === 'string'){
|
|
188
|
+
return `'${param}'`
|
|
189
|
+
}
|
|
190
|
+
return param
|
|
191
|
+
}).toString()
|
|
192
|
+
sql_step.p2 = toParamBytes(result, crc);
|
|
193
|
+
}
|
|
194
|
+
sql_step.pcrc = crc.value;
|
|
323
195
|
}
|
|
324
|
-
}
|
|
325
196
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
197
|
+
const result = original.apply(this, args);
|
|
198
|
+
|
|
199
|
+
return result.then(res => {
|
|
200
|
+
if (Array.isArray(res) && psql && psql.type === "S") {
|
|
201
|
+
var result_step = new ResultSetStep();
|
|
202
|
+
result_step.start_time = ctx.getElapsedTime();
|
|
203
|
+
result_step.elapsed = 0;
|
|
204
|
+
result_step.fetch = res.length;
|
|
205
|
+
result_step.sqlhash = psql.sql;
|
|
206
|
+
result_step.dbc = dbc_hash;
|
|
207
|
+
ctx.profile.push(result_step);
|
|
208
|
+
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
|
|
209
|
+
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
|
|
210
|
+
|
|
211
|
+
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
|
|
212
|
+
}
|
|
213
|
+
var isSelectQuery = psql && psql.type === "S"? true : false;
|
|
214
|
+
_finishQuery(ctx, sql_step, isSelectQuery, res);
|
|
215
|
+
return res;
|
|
216
|
+
}).catch(err => {
|
|
217
|
+
_handleError(ctx, sql_step, err)
|
|
218
|
+
if (conf.trace_sql_error_stack && conf.trace_sql_error_depth) {
|
|
219
|
+
var traceDepth = conf.trace_sql_error_depth;
|
|
220
|
+
|
|
221
|
+
var errorStack = err.stack.split("\n");
|
|
222
|
+
if (errorStack.length > traceDepth) {
|
|
223
|
+
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
224
|
+
}
|
|
225
|
+
ctx.error_message = errorStack.join("\n");
|
|
226
|
+
sql_step.error = ctx.error = StatError.addError('pgsql -' + err.code, err.message, ctx.service_hash, TextTypes.SQL, null);
|
|
227
|
+
}
|
|
228
|
+
throw err;
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
var toParamBytes = function (p, crc) {
|
|
235
|
+
if (p == null || p.length === 0) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
return ParamSecurity.encrypt(Buffer.from(p, 'utf8'), crc);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
339
243
|
};
|
|
340
244
|
|
|
245
|
+
function getDBCHash(args) {
|
|
246
|
+
dbc = `mariadb://${(args[0] || {}).user || ''}@${(args[0] || {}).host || ''}/${(args[0] || {}).database || ''}`;
|
|
247
|
+
dbc_hash = HashUtil.hashFromString(dbc);
|
|
248
|
+
}
|
|
249
|
+
|
|
341
250
|
var checkedSql = new IntKeyMap(2000).setMax(2000);
|
|
342
251
|
var nonLiteSql = new IntKeyMap(5000).setMax(5000);
|
|
343
252
|
var date = DateUtil.yyyymmdd();
|
|
@@ -19,7 +19,8 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
19
19
|
TextTypes = require('../lang/text-types'),
|
|
20
20
|
Long = require('long'),
|
|
21
21
|
conf = require('../conf/configure'),
|
|
22
|
-
Logger = require('../logger')
|
|
22
|
+
Logger = require('../logger'),
|
|
23
|
+
TraceSQL = require('../trace/trace-sql')
|
|
23
24
|
const DateUtil = require('../util/dateutil');
|
|
24
25
|
const MessageStep = require("../step/message-step");
|
|
25
26
|
// const ResourceProfile = require("../util/resourceprofile");
|
|
@@ -101,48 +102,41 @@ MssqlObserver.prototype.inject = function (mod, modName) {
|
|
|
101
102
|
if (errorStack.length > traceDepth) {
|
|
102
103
|
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
error_stack_step.hash = HashUtil.hashFromString("ERROR STACK");
|
|
107
|
-
error_stack_step.start_time = ctx.getElapsedTime();
|
|
108
|
-
error_stack_step.desc = errorStackString;
|
|
109
|
-
DataTextAgent.MESSAGE.add(error_stack_step.hash, "ERROR STACK");
|
|
110
|
-
ctx.profile.push(error_stack_step);
|
|
105
|
+
ctx.error_message = errorStack.join("\n");
|
|
106
|
+
sql_step.error = ctx.error = StatError.addError('mssql-' + args[0].code, args[0].message, ctx.service_hash, TextTypes.SQL, null);
|
|
111
107
|
}
|
|
112
108
|
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
113
|
-
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL,
|
|
109
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
114
110
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
115
111
|
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
116
|
-
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL,
|
|
112
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
117
113
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
118
114
|
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
119
|
-
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL,
|
|
115
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
120
116
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
121
117
|
}
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
121
|
+
TraceSQL.isSlowSQL(ctx);
|
|
125
122
|
|
|
126
123
|
MeterSql.add(dbc_hash, sql_step.elapsed, args[0] != null);
|
|
127
124
|
StatSql.addSqlTime(ctx.service_hash, sql_step.dbc,
|
|
128
125
|
sql_step.hash, sql_step.elapsed, args[0] != null, 0);
|
|
129
126
|
|
|
130
|
-
// if(conf.getProperty('profile_sql_resource_enabled', false)){
|
|
131
|
-
// sql_step.start_cpu = ResourceProfile.getCPUTime();
|
|
132
|
-
// sql_step.start_mem = ResourceProfile.getUsedHeapSize();
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
127
|
if(psql && psql.type == 'S') {
|
|
136
128
|
var result_step = new ResultSetStep();
|
|
137
129
|
result_step.dbc = sql_step.dbc;
|
|
138
130
|
result_step.sqlhash = sql_step.hash;
|
|
139
131
|
try {
|
|
140
|
-
result_step.fetch = args[1].
|
|
132
|
+
result_step.fetch = args[1][0].length;
|
|
141
133
|
} catch(e) {
|
|
142
134
|
}
|
|
143
135
|
ctx.profile.push(result_step);
|
|
144
136
|
MeterSql.addFetch(dbc_hash, result_step.fetch, 0);
|
|
145
137
|
StatSql.addFetch(dbc_hash, result_step.sqlhash, result_step.fetch, 0);
|
|
138
|
+
|
|
139
|
+
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
|
|
146
140
|
} else if(psql && psql.type == 'U') {
|
|
147
141
|
|
|
148
142
|
}
|
|
@@ -23,8 +23,7 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
23
23
|
conf = require('../conf/configure'),
|
|
24
24
|
DateUtil = require('../util/dateutil'),
|
|
25
25
|
Buffer = require('buffer').Buffer,
|
|
26
|
-
|
|
27
|
-
// const ResourceProfile = require('../util/resourceprofile');
|
|
26
|
+
TraceSQL = require('../trace/trace-sql');
|
|
28
27
|
|
|
29
28
|
var MysqlObserver = function (agent) {
|
|
30
29
|
this.agent = agent;
|
|
@@ -126,26 +125,21 @@ var queryHook = function (dbc, agent) {
|
|
|
126
125
|
if (errorStack.length > traceDepth) {
|
|
127
126
|
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
128
127
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
error_stack_step.hash = HashUtil.hashFromString("ERROR STACK");
|
|
132
|
-
error_stack_step.start_time = ctx.getElapsedTime();
|
|
133
|
-
error_stack_step.desc = errorStackString;
|
|
134
|
-
DataTextAgent.MESSAGE.add(error_stack_step.hash, "ERROR STACK");
|
|
135
|
-
ctx.profile.push(error_stack_step);
|
|
128
|
+
ctx.error_message = errorStack.join("\n");
|
|
129
|
+
sql_step.error = ctx.error = StatError.addError('mysql-' + args[0].code, args[0].sqlMessage, ctx.service_hash, TextTypes.SQL, null);
|
|
136
130
|
}
|
|
137
131
|
if (conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0) {
|
|
138
|
-
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL,
|
|
132
|
+
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
139
133
|
if (ctx.error.isZero()) {
|
|
140
134
|
ctx.error = sql_step.error;
|
|
141
135
|
}
|
|
142
136
|
} else if (conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0) {
|
|
143
|
-
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL,
|
|
137
|
+
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
144
138
|
if (ctx.error.isZero()) {
|
|
145
139
|
ctx.error = sql_step.error;
|
|
146
140
|
}
|
|
147
141
|
} else if (conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
148
|
-
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL,
|
|
142
|
+
sql_step.error = StatError.addError('mysql-' + args[0].code, args[0].message || 'mysql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
149
143
|
if (ctx.error.isZero()) {
|
|
150
144
|
ctx.error = sql_step.error;
|
|
151
145
|
}
|
|
@@ -168,6 +162,8 @@ var queryHook = function (dbc, agent) {
|
|
|
168
162
|
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
169
163
|
ctx.sql_time += sql_step.elapsed;
|
|
170
164
|
|
|
165
|
+
TraceSQL.isSlowSQL(ctx);
|
|
166
|
+
|
|
171
167
|
// if(conf.getProperty('profile_sql_resource_enabled', false)){
|
|
172
168
|
// sql_step.start_cpu = ResourceProfile.getCPUTime();
|
|
173
169
|
// sql_step.start_mem = ResourceProfile.getUsedHeapSize();
|
|
@@ -189,6 +185,8 @@ var queryHook = function (dbc, agent) {
|
|
|
189
185
|
ctx.profile.push(result_step);
|
|
190
186
|
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
|
|
191
187
|
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
|
|
188
|
+
|
|
189
|
+
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
|
|
192
190
|
}
|
|
193
191
|
|
|
194
192
|
if (args[1] != null && psql != null && psql.type === 'U') {
|