whatap 0.5.1 → 0.5.2
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.
|
@@ -199,11 +199,12 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
|
|
|
199
199
|
ctx.status = Math.floor(obj.statusCode / 100);
|
|
200
200
|
|
|
201
201
|
// 에러가 발생했지만 스택수집안했을 경우
|
|
202
|
-
if (transaction_status_error_enable && ctx.status >= 4
|
|
203
|
-
ctx.error
|
|
204
|
-
ctx.service_hash);
|
|
202
|
+
if (transaction_status_error_enable && ctx.status >= 4) {
|
|
203
|
+
if(ctx.error.isZero())
|
|
204
|
+
ctx.error = StatError.addError(obj.statusCode, obj.statusMessage, ctx.service_hash);
|
|
205
205
|
ctx.statusCode = obj.statusCode;
|
|
206
|
-
ctx.
|
|
206
|
+
ctx.statusTitle = obj.statusMessage;
|
|
207
|
+
ctx.statusMessage = ctx.error_message;
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
var requestPath = '';
|
|
@@ -469,10 +470,11 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
469
470
|
|
|
470
471
|
if(profile_error_step_enabled && ctx.statusMessage){
|
|
471
472
|
var step = new MessageStep();
|
|
472
|
-
|
|
473
|
+
var title = ctx.statusTitle ? ctx.statusTitle : "EXCEPTION";
|
|
474
|
+
step.hash = HashUtil.hashFromString(title);
|
|
473
475
|
step.start_time = ctx.getElapsedTime();
|
|
474
476
|
step.desc = ctx.statusMessage;
|
|
475
|
-
DataTextAgent.MESSAGE.add(step.hash,
|
|
477
|
+
DataTextAgent.MESSAGE.add(step.hash, title);
|
|
476
478
|
ctx.profile.push(step);
|
|
477
479
|
}
|
|
478
480
|
|
|
@@ -667,7 +669,7 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
|
|
|
667
669
|
moduleName === 'https', obj);
|
|
668
670
|
});
|
|
669
671
|
|
|
670
|
-
if( conf.httpc_enabled === false ) { return; }
|
|
672
|
+
if( conf.getProperty('httpc_enabled', true) === false ) { return; }
|
|
671
673
|
|
|
672
674
|
aop.both(mod, 'request',
|
|
673
675
|
function (obj, args, lctx) {
|
|
@@ -23,321 +23,213 @@ 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
|
+
shimmer = require('../core/shimmer');
|
|
28
27
|
|
|
29
28
|
var MariaObserver = function (agent) {
|
|
30
29
|
this.agent = agent;
|
|
31
30
|
this.packages = ['mariadb'];
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
var dbc, dbc_hash;
|
|
34
|
+
MariaObserver.prototype.inject = function (mod, moduleName) {
|
|
35
|
+
if (mod.__whatap_observe__) { return; }
|
|
36
|
+
mod.__whatap_observe__ = true;
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
if(args[0].sql == null && typeof args[0] != 'string') { return; }
|
|
38
|
+
Logger.initPrint("MariaObserver");
|
|
41
39
|
|
|
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)
|
|
40
|
+
if (!conf.sql_enabled) return;
|
|
47
41
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
// shimmer.wrap(mod, 'createConnection', wrapCreateConnection(mod));
|
|
43
|
+
shimmer.wrap(mod, 'createConnection', wrapConnection(mod));
|
|
44
|
+
shimmer.wrap(mod, 'createPool', wrapCreatePool(mod));
|
|
45
|
+
};
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
ctx.profile.push(sql_step);
|
|
47
|
+
var _finishQuery = function (ctx, sql_step) {
|
|
48
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
55
49
|
|
|
56
|
-
|
|
50
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
51
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, false, 0);
|
|
52
|
+
};
|
|
57
53
|
|
|
58
|
-
|
|
54
|
+
var _handleError = function (ctx, sql_step, err) {
|
|
55
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
58
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0);
|
|
59
|
+
};
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
function wrapCreateConnection(agent) {
|
|
62
|
+
return function (original) {
|
|
63
|
+
return async function (...args) {
|
|
64
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
65
|
+
if (!ctx || ctx.db_opening) return original.apply(this, args);
|
|
66
66
|
|
|
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
|
-
}
|
|
67
|
+
ctx.db_opening = true;
|
|
68
|
+
ctx.footprint('Maria Connecting Start');
|
|
77
69
|
|
|
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
|
-
}
|
|
70
|
+
// const dbc_step = new DBCStep();
|
|
71
|
+
// dbc_step.start_time = ctx.getElapsedTime();
|
|
107
72
|
|
|
108
|
-
|
|
73
|
+
const connection = await original.apply(this, args);
|
|
74
|
+
wrapConnectionMethods(connection, agent);
|
|
109
75
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
TraceContextManager.resume(ctx._id);
|
|
76
|
+
ctx.footprint('Maria Connecting Done');
|
|
77
|
+
ctx.db_opening = false;
|
|
113
78
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var traceDepth = conf.trace_sql_error_depth;
|
|
79
|
+
getDBCHash(args);
|
|
80
|
+
// dbc_step.hash = dbc_hash;
|
|
81
|
+
// ctx.profile.push(dbc_step);
|
|
118
82
|
|
|
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
|
-
}
|
|
83
|
+
return connection;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
145
87
|
|
|
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
|
-
}
|
|
88
|
+
function wrapConnection(agent) {
|
|
89
|
+
return function (original) {
|
|
90
|
+
return function (...args) {
|
|
91
|
+
const connectionPromise = original.apply(this, args);
|
|
92
|
+
getDBCHash(args);
|
|
171
93
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
94
|
+
return connectionPromise.then(connection => {
|
|
95
|
+
shimmer.wrap(connection, 'query', createQueryHook(agent));
|
|
96
|
+
return connection;
|
|
97
|
+
});
|
|
176
98
|
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
177
101
|
|
|
178
|
-
|
|
102
|
+
function wrapCreatePool(agent) {
|
|
103
|
+
return function (original) {
|
|
104
|
+
return function (...args) {
|
|
105
|
+
const pool = original.apply(this, args);
|
|
106
|
+
getDBCHash(args);
|
|
107
|
+
|
|
108
|
+
shimmer.wrap(pool, 'getConnection', (originalGetConnection) => {
|
|
109
|
+
return async function (...connArgs) {
|
|
110
|
+
const connection = await originalGetConnection.apply(this, connArgs);
|
|
111
|
+
wrapConnectionMethods(connection, agent);
|
|
112
|
+
return connection;
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return pool;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
179
120
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
121
|
+
function wrapConnectionMethods(connection, agent) {
|
|
122
|
+
shimmer.wrap(connection, 'query', createQueryHook(agent));
|
|
123
|
+
shimmer.wrap(connection, 'execute', createQueryHook(agent));
|
|
124
|
+
}
|
|
185
125
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return ParamSecurity.encrypt(Buffer.from(p), crc);
|
|
192
|
-
} catch(e) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
126
|
+
function createQueryHook(agent) {
|
|
127
|
+
return function (original) {
|
|
128
|
+
return function (...args) {
|
|
129
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
130
|
+
if (!ctx || !args[0]) return original.apply(this, args);
|
|
196
131
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
var ctx = TraceContextManager.getCurrentContext();
|
|
200
|
-
if(ctx == null) { return; }
|
|
132
|
+
ctx.db_opening = true;
|
|
133
|
+
ctx.footprint('Maria Connecting Start');
|
|
201
134
|
|
|
202
|
-
|
|
203
|
-
|
|
135
|
+
const dbc_step = new DBCStep();
|
|
136
|
+
ctx.footprint('Maria Connecting Done');
|
|
137
|
+
ctx.db_opening = false;
|
|
204
138
|
|
|
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
|
-
}
|
|
139
|
+
dbc_step.hash = dbc_hash;
|
|
140
|
+
ctx.profile.push(dbc_step);
|
|
210
141
|
|
|
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
|
-
};
|
|
142
|
+
const sql_step = new SqlStepX();
|
|
143
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
144
|
+
ctx.profile.push(sql_step);
|
|
232
145
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
mod.__whatap_observe__ = true;
|
|
238
|
-
Logger.initPrint("MariaObserver");
|
|
239
|
-
var self = this;
|
|
240
|
-
var aop = self.agent.aop;
|
|
146
|
+
ctx.footprint('Maria Query Start');
|
|
147
|
+
ctx.sql_count++;
|
|
241
148
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
149
|
+
var sql = args.length > 0 ? args[0] : undefined,
|
|
150
|
+
psql = null;
|
|
245
151
|
|
|
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;
|
|
152
|
+
if(typeof sql !== 'string') {
|
|
153
|
+
sql = args[0].sql || undefined;
|
|
253
154
|
}
|
|
254
|
-
ctx.db_opening = true;
|
|
255
|
-
ctx.footprint('Maria Connecting Start');
|
|
256
155
|
|
|
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);
|
|
156
|
+
if (typeof sql === 'string' && sql.length > 0) {
|
|
157
|
+
try {
|
|
158
|
+
psql = escapeLiteral(sql);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
Logger.printError('WHATAP-191', 'MariaObserver escapeliteral error', e);
|
|
275
161
|
}
|
|
162
|
+
} else {
|
|
163
|
+
sql = '';
|
|
164
|
+
psql = escapeLiteral(sql);
|
|
276
165
|
}
|
|
277
166
|
|
|
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;
|
|
167
|
+
if(psql != null) {
|
|
168
|
+
sql_step.hash = psql.sql;
|
|
169
|
+
// sql_step.crud = psql.type.charCodeAt(0);
|
|
304
170
|
}
|
|
305
171
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
172
|
+
var els = new EscapeLiteralSQL(sql);
|
|
173
|
+
els.process();
|
|
174
|
+
|
|
175
|
+
ctx.active_sqlhash = sql_step.hash;
|
|
176
|
+
|
|
177
|
+
if(conf.profile_sql_param_enabled) {
|
|
178
|
+
var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
|
|
179
|
+
sql_step.setTrue(1);
|
|
180
|
+
var crc = {value : 0};
|
|
181
|
+
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
182
|
+
if(params != undefined) {
|
|
183
|
+
const result = params.map((param) => {
|
|
184
|
+
if(typeof param === 'string'){
|
|
185
|
+
return `'${param}'`
|
|
186
|
+
}
|
|
187
|
+
return param
|
|
188
|
+
}).toString()
|
|
189
|
+
sql_step.p2 = toParamBytes(result, crc);
|
|
190
|
+
}
|
|
191
|
+
sql_step.pcrc = crc.value;
|
|
323
192
|
}
|
|
324
|
-
}
|
|
325
193
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
194
|
+
const result = original.apply(this, args);
|
|
195
|
+
// return result;
|
|
196
|
+
return result.then(res => {
|
|
197
|
+
_finishQuery(ctx, sql_step);
|
|
198
|
+
return res;
|
|
199
|
+
}).catch(err => {
|
|
200
|
+
_handleError(ctx, sql_step, err)
|
|
201
|
+
if (conf.trace_sql_error_stack && conf.trace_sql_error_depth) {
|
|
202
|
+
var traceDepth = conf.trace_sql_error_depth;
|
|
203
|
+
|
|
204
|
+
var errorStack = err.stack.split("\n");
|
|
205
|
+
if (errorStack.length > traceDepth) {
|
|
206
|
+
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
207
|
+
}
|
|
208
|
+
ctx.error_message = errorStack.join("\n");
|
|
209
|
+
sql_step.error = ctx.error = StatError.addError('pgsql -' + err.code, err.message, ctx.service_hash, TextTypes.SQL, null);
|
|
210
|
+
}
|
|
211
|
+
throw err;
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
var toParamBytes = function (p, crc) {
|
|
218
|
+
if (p == null || p.length === 0) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
return ParamSecurity.encrypt(Buffer.from(p, 'utf8'), crc);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
339
226
|
};
|
|
340
227
|
|
|
228
|
+
function getDBCHash(args) {
|
|
229
|
+
dbc = `mariadb://${(args[0] || {}).user || ''}@${(args[0] || {}).host || ''}/${(args[0] || {}).database || ''}`;
|
|
230
|
+
dbc_hash = HashUtil.hashFromString(dbc);
|
|
231
|
+
}
|
|
232
|
+
|
|
341
233
|
var checkedSql = new IntKeyMap(2000).setMax(2000);
|
|
342
234
|
var nonLiteSql = new IntKeyMap(5000).setMax(5000);
|
|
343
235
|
var date = DateUtil.yyyymmdd();
|
|
@@ -101,22 +101,17 @@ MssqlObserver.prototype.inject = function (mod, modName) {
|
|
|
101
101
|
if (errorStack.length > traceDepth) {
|
|
102
102
|
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
103
103
|
}
|
|
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);
|
|
104
|
+
ctx.error_message = errorStack.join("\n");
|
|
105
|
+
sql_step.error = ctx.error = StatError.addError('mssql-' + args[0].code, args[0].message, ctx.service_hash, TextTypes.SQL, null);
|
|
111
106
|
}
|
|
112
107
|
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,
|
|
108
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
114
109
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
115
110
|
} 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,
|
|
111
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
117
112
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
118
113
|
} 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,
|
|
114
|
+
sql_step.error = StatError.addError( 'mssql-'+args[0].code, args[0].message|| 'mssql error', ctx.service_hash, TextTypes.SQL, sql_step.hash); /*long*/
|
|
120
115
|
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
121
116
|
}
|
|
122
117
|
}
|
|
@@ -22,8 +22,7 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
22
22
|
Logger = require('../logger'),
|
|
23
23
|
conf = require('../conf/configure'),
|
|
24
24
|
DateUtil = require('../util/dateutil'),
|
|
25
|
-
Buffer = require('buffer').Buffer
|
|
26
|
-
MessageStep = require("../step/message-step");
|
|
25
|
+
Buffer = require('buffer').Buffer;
|
|
27
26
|
// const ResourceProfile = require('../util/resourceprofile');
|
|
28
27
|
|
|
29
28
|
var MysqlObserver = function (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
|
}
|
|
@@ -8,7 +8,6 @@ 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'),
|
|
11
|
-
ResultSetStep = require('../step/resultset-step'),
|
|
12
11
|
DataTextAgent = require('../data/datatext-agent'),
|
|
13
12
|
StatSql = require('../stat/stat-sql'),
|
|
14
13
|
MeterSql = require('../counter/meter/meter-sql'),
|
|
@@ -20,148 +19,228 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
20
19
|
TextTypes = require('../lang/text-types'),
|
|
21
20
|
ParamSecurity = require('../util/paramsecurity'),
|
|
22
21
|
Logger = require('../logger'),
|
|
23
|
-
conf = require('../conf/configure'),
|
|
24
22
|
Buffer = require('buffer').Buffer,
|
|
25
|
-
DateUtil
|
|
26
|
-
|
|
27
|
-
// const ResourceProfile = require("../util/resourceprofile");
|
|
23
|
+
DateUtil = require('../util/dateutil');
|
|
24
|
+
const shimmer = require('../core/shimmer');
|
|
28
25
|
|
|
29
26
|
var PgSqlObserver = function (agent) {
|
|
30
27
|
this.agent = agent;
|
|
31
28
|
this.packages = ['pg'];
|
|
32
29
|
};
|
|
33
30
|
|
|
34
|
-
var
|
|
31
|
+
var dbc_hash = 0;
|
|
32
|
+
var dbc, dbc_step;
|
|
33
|
+
PgSqlObserver.prototype.inject = function (mod, moduleName) {
|
|
34
|
+
if (mod.__whatap_observe__) { return; }
|
|
35
|
+
mod.__whatap_observe__ = true;
|
|
36
|
+
|
|
37
|
+
Logger.initPrint("PgSqlObserver");
|
|
38
|
+
|
|
39
|
+
var self = this;
|
|
40
|
+
var aop = self.agent.aop;
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
if (conf.sql_enabled === false) { return; }
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
shimmer.wrap(mod.Client.prototype, 'connect', function (original) {
|
|
45
|
+
return function () {
|
|
46
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
47
|
+
if (!ctx || ctx.db_opening) {
|
|
48
|
+
return original.apply(this, arguments);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
ctx.pg_opening = true;
|
|
52
|
+
ctx.footprint('PgSql Connecting Start');
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ctx.profile.push(sql_step);
|
|
46
|
-
ctx.footprint('PgSql Query Start');
|
|
54
|
+
dbc_step = new DBCStep();
|
|
55
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
47
56
|
|
|
48
|
-
|
|
57
|
+
const finishConnect = function (param) {
|
|
58
|
+
if (ctx) {
|
|
59
|
+
if (dbc_hash === 0) {
|
|
60
|
+
const info = param.connectionParameters;
|
|
61
|
+
dbc = 'postgresql://';
|
|
62
|
+
dbc += (info.user || '') + '@';
|
|
63
|
+
dbc += (info.host || '') + '/';
|
|
64
|
+
dbc += info.database || '';
|
|
49
65
|
|
|
50
|
-
|
|
51
|
-
psql = null;
|
|
66
|
+
dbc_hash = HashUtil.hashFromString(dbc);
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
// DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
69
|
+
// DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
70
|
+
// DataTextAgent.ERROR.add(dbc_hash, dbc);
|
|
71
|
+
}
|
|
72
|
+
//
|
|
73
|
+
// dbc_step.hash = dbc_hash;
|
|
74
|
+
// dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
75
|
+
//
|
|
76
|
+
// ctx.db_opening = false;
|
|
77
|
+
// ctx.footprint('PgSql Connecting Done');
|
|
78
|
+
// ctx.profile.push(dbc_step);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
56
81
|
|
|
57
|
-
if (typeof sql === 'string' && sql.length > 0) {
|
|
58
82
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
83
|
+
const result = original.apply(this, arguments);
|
|
84
|
+
|
|
85
|
+
if (result && result.then) {
|
|
86
|
+
result.then(finishConnect(this));
|
|
87
|
+
} else {
|
|
88
|
+
finishConnect(this);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
} catch (err) {
|
|
92
|
+
ctx.db_opening = false;
|
|
93
|
+
Logger.printError('PgSqlObserver', 'Connect Error', err);
|
|
94
|
+
throw err;
|
|
62
95
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
sql_step.dbc = dbc_hash;
|
|
73
|
-
|
|
74
|
-
var els = new EscapeLiteralSQL(sql);
|
|
75
|
-
els.process();
|
|
76
|
-
|
|
77
|
-
ctx.active_sqlhash = sql_step.hash;
|
|
78
|
-
ctx.active_dbc = sql_step.dbc;
|
|
79
|
-
//ctx.active_crud = sql_step.crud;
|
|
80
|
-
|
|
81
|
-
if(conf.profile_sql_param_enabled) {
|
|
82
|
-
var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
|
|
83
|
-
sql_step.setTrue(1);
|
|
84
|
-
var crc = {value : 0};
|
|
85
|
-
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
86
|
-
if(params != undefined) {
|
|
87
|
-
const result = params.map((param) => {
|
|
88
|
-
if(typeof param === 'string'){
|
|
89
|
-
return `'${param}'`
|
|
90
|
-
}
|
|
91
|
-
return param
|
|
92
|
-
}).toString()
|
|
93
|
-
sql_step.p2 = toParamBytes(result, crc);
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
shimmer.wrap(mod.Client.prototype, 'query', function (original) {
|
|
100
|
+
return function () {
|
|
101
|
+
const ctx = TraceContextManager.getCurrentContext();
|
|
102
|
+
if (!ctx) {
|
|
103
|
+
return original.apply(this, arguments);
|
|
94
104
|
}
|
|
95
|
-
sql_step.pcrc = crc.value;
|
|
96
|
-
}
|
|
97
105
|
|
|
98
|
-
|
|
106
|
+
if(dbc && dbc_hash){
|
|
107
|
+
if(!dbc_step){
|
|
108
|
+
dbc_step = new DBCStep();
|
|
109
|
+
dbc_step.start_time = ctx.getElapsedTime();
|
|
110
|
+
}
|
|
111
|
+
dbc_step.elapsed = ctx.getElapsedTime() - dbc_step.start_time;
|
|
112
|
+
dbc_step.hash = dbc_hash;
|
|
113
|
+
|
|
114
|
+
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
115
|
+
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
116
|
+
DataTextAgent.ERROR.add(dbc_hash, dbc);
|
|
117
|
+
|
|
118
|
+
ctx.pg_opening = false;
|
|
119
|
+
ctx.footprint('PgSql Connecting Done');
|
|
120
|
+
ctx.profile.push(dbc_step);
|
|
121
|
+
}
|
|
122
|
+
dbc_step = null;
|
|
99
123
|
|
|
100
|
-
|
|
124
|
+
var sql_step = new SqlStepX();
|
|
125
|
+
sql_step.start_time = ctx.getElapsedTime();
|
|
126
|
+
ctx.profile.push(sql_step);
|
|
127
|
+
ctx.footprint('PgSql Query Start');
|
|
101
128
|
|
|
102
|
-
|
|
103
|
-
TraceContextManager.resume(ctx._id);
|
|
129
|
+
ctx.vvv++;
|
|
104
130
|
|
|
105
|
-
|
|
131
|
+
let sql = arguments[0];
|
|
132
|
+
let psql = null;
|
|
133
|
+
if (typeof sql === 'string' && sql.length > 0) {
|
|
106
134
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
psql = escapeLiteral(sql);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
Logger.printError('WHATAP-191', 'PgSqlObserver escapeliteral error', e);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
sql = '';
|
|
141
|
+
psql = escapeLiteral(sql);
|
|
142
|
+
}
|
|
109
143
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
144
|
+
if(psql != null) {
|
|
145
|
+
sql_step.hash = psql.sql;
|
|
146
|
+
}
|
|
147
|
+
sql_step.dbc = dbc_hash;
|
|
148
|
+
|
|
149
|
+
var els = new EscapeLiteralSQL(sql);
|
|
150
|
+
els.process();
|
|
151
|
+
ctx.active_sqlhash = sql_step.hash;
|
|
152
|
+
ctx.active_dbc = sql_step.dbc;
|
|
153
|
+
//ctx.active_crud = sql_step.crud;
|
|
154
|
+
|
|
155
|
+
if(conf.profile_sql_param_enabled) {
|
|
156
|
+
var params = arguments.length > 1 && Array.isArray(arguments[1]) ? arguments[1] : undefined;
|
|
157
|
+
sql_step.setTrue(1);
|
|
158
|
+
var crc = {value : 0};
|
|
159
|
+
sql_step.p1 = toParamBytes(psql.param, crc);
|
|
160
|
+
if(params != undefined) {
|
|
161
|
+
const result = params.map((param) => {
|
|
162
|
+
if(typeof param === 'string'){
|
|
163
|
+
return `'${param}'`
|
|
113
164
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
error_stack_step.start_time = ctx.getElapsedTime();
|
|
118
|
-
error_stack_step.desc = errorStackString;
|
|
119
|
-
DataTextAgent.MESSAGE.add(error_stack_step.hash, "ERROR STACK");
|
|
120
|
-
ctx.profile.push(error_stack_step);
|
|
121
|
-
}
|
|
122
|
-
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
123
|
-
sql_step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message|| 'pgsql error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
124
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
125
|
-
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
126
|
-
sql_step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message|| 'pgsql error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
127
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
128
|
-
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
129
|
-
sql_step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message|| 'pgsql error', ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
130
|
-
if (ctx.error.isZero()) { ctx.error = sql_step.error; }
|
|
131
|
-
}
|
|
132
|
-
} catch (e) {
|
|
165
|
+
return param
|
|
166
|
+
}).toString()
|
|
167
|
+
sql_step.p2 = toParamBytes(result, crc);
|
|
133
168
|
}
|
|
169
|
+
sql_step.pcrc = crc.value;
|
|
134
170
|
}
|
|
135
171
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
try {
|
|
173
|
+
// SQL 실행
|
|
174
|
+
const result = original.apply(this, arguments);
|
|
175
|
+
|
|
176
|
+
if (result && result.then) {
|
|
177
|
+
return result.then(res => {
|
|
178
|
+
self._finishQuery(ctx, sql_step);
|
|
179
|
+
return res;
|
|
180
|
+
}).catch(err => {
|
|
181
|
+
self._handleError(ctx, sql_step, err)
|
|
182
|
+
if (conf.trace_sql_error_stack && conf.trace_sql_error_depth) {
|
|
183
|
+
var traceDepth = conf.trace_sql_error_depth;
|
|
184
|
+
|
|
185
|
+
var errorStack = err.stack.split("\n");
|
|
186
|
+
if (errorStack.length > traceDepth) {
|
|
187
|
+
errorStack = errorStack.slice(0, traceDepth + 1);
|
|
188
|
+
}
|
|
189
|
+
ctx.error_message = errorStack.join("\n");
|
|
190
|
+
sql_step.error = ctx.error = StatError.addError('pgsql -' + err.code, err.message, ctx.service_hash, TextTypes.SQL, null);
|
|
191
|
+
}
|
|
192
|
+
throw err;
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
const callback = arguments[arguments.length - 1];
|
|
196
|
+
if (typeof callback === 'function') {
|
|
197
|
+
arguments[arguments.length - 1] = function (err, res) {
|
|
198
|
+
if (err) {
|
|
199
|
+
self._handleError(ctx, sql_step, err);
|
|
200
|
+
} else {
|
|
201
|
+
self._finishQuery(ctx, sql_step);
|
|
202
|
+
}
|
|
203
|
+
return callback.apply(this, arguments);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
} catch (err) {
|
|
209
|
+
self._handleError(ctx, sql_step, err);
|
|
210
|
+
throw err;
|
|
160
211
|
}
|
|
161
|
-
}
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// if (mod.Pool && mod.Pool.prototype.query) {
|
|
216
|
+
// shimmer.wrap(mod.Pool.prototype, 'query', function (original) {
|
|
217
|
+
// return function () {
|
|
218
|
+
// const traceContext = TraceContextManager.getCurrentContext();
|
|
219
|
+
// if (!traceContext) {
|
|
220
|
+
// return original.apply(this, arguments);
|
|
221
|
+
// }
|
|
222
|
+
//
|
|
223
|
+
// // 동일한 방식으로 처리
|
|
224
|
+
// return self.agent.pgClient.query.apply(this, arguments);
|
|
225
|
+
// };
|
|
226
|
+
// });
|
|
227
|
+
// }
|
|
228
|
+
};
|
|
162
229
|
|
|
163
|
-
|
|
164
|
-
|
|
230
|
+
// 쿼리 완료 처리
|
|
231
|
+
PgSqlObserver.prototype._finishQuery = function (ctx, sql_step) {
|
|
232
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
233
|
+
|
|
234
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
235
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, false, 0);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
PgSqlObserver.prototype._handleError = function (ctx, sql_step, err) {
|
|
239
|
+
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
|
|
240
|
+
|
|
241
|
+
// Logger.printError('WHATAP-192', 'PGSQL Query error.', err);
|
|
242
|
+
MeterSql.add(sql_step.hash, sql_step.elapsed, false);
|
|
243
|
+
StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0);
|
|
165
244
|
};
|
|
166
245
|
|
|
167
246
|
var toParamBytes = function(p, crc) {
|
|
@@ -175,105 +254,6 @@ var toParamBytes = function(p, crc) {
|
|
|
175
254
|
}
|
|
176
255
|
};
|
|
177
256
|
|
|
178
|
-
var errorDelegate = function () {
|
|
179
|
-
return function (obj, args) {
|
|
180
|
-
|
|
181
|
-
var ctx = TraceContextManager.getCurrentContext();
|
|
182
|
-
if(ctx == null) { return; }
|
|
183
|
-
|
|
184
|
-
var laststep = ctx.profile.getLastSteps(1);
|
|
185
|
-
if(laststep == null || laststep.length === 0) { return; }
|
|
186
|
-
|
|
187
|
-
var step = laststep[0];
|
|
188
|
-
if(!args[0].fatal) {
|
|
189
|
-
MeterSql.add(step.dbc, step.elapsed, true);
|
|
190
|
-
StatSql.addSqlTime(ctx.service_hash, step.dbc, step.hash, step.elapsed, true, 0);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
try{
|
|
194
|
-
if(args[0].fatal) {
|
|
195
|
-
// Connection Error
|
|
196
|
-
step.error = StatError.addError("pgsql-"+args[0].code, args[0].message, ctx.service_hash); /*long*/
|
|
197
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
198
|
-
} else {
|
|
199
|
-
if(conf._is_trace_ignore_err_cls_contains === true && args[0].code.indexOf(conf.trace_ignore_err_cls_contains) < 0){
|
|
200
|
-
step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message, ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
201
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
202
|
-
} else if(conf._is_trace_ignore_err_msg_contains === true && args[0].message.indexOf(conf.trace_ignore_err_msg_contains) < 0){
|
|
203
|
-
step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message, ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
204
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
205
|
-
} else if(conf._is_trace_ignore_err_cls_contains === false && conf._is_trace_ignore_err_msg_contains === false) {
|
|
206
|
-
step.error = StatError.addError( 'pgsql-'+args[0].code, args[0].message, ctx.service_hash, TextTypes.SQL, step.hash); /*long*/
|
|
207
|
-
if (ctx.error.isZero()) { ctx.error = step.error; }
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} catch(e) {
|
|
211
|
-
Logger.printError('WHATAP-997', 'pgsql-observer (errorDelegate)', e, true);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
var dbc_hash=0;
|
|
217
|
-
PgSqlObserver.prototype.inject = function (mod, moduleName) {
|
|
218
|
-
if(mod.__whatap_observe__) { return; }
|
|
219
|
-
mod.__whatap_observe__ = true;
|
|
220
|
-
|
|
221
|
-
Logger.initPrint("PgSqlObserver");
|
|
222
|
-
|
|
223
|
-
var self = this;
|
|
224
|
-
var aop = self.agent.aop;
|
|
225
|
-
|
|
226
|
-
if( conf.sql_enabled === false ) { return; }
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
aop.both(mod.Client.prototype, 'connect',
|
|
230
|
-
function (obj, args, lctx) {
|
|
231
|
-
var ctx = lctx.context;
|
|
232
|
-
if(ctx == null || ctx.db_opening) { return; }
|
|
233
|
-
ctx.db_opening = true;
|
|
234
|
-
|
|
235
|
-
ctx.footprint('PgSql Connecting Start');
|
|
236
|
-
|
|
237
|
-
var dbc_step = new DBCStep();
|
|
238
|
-
dbc_step.start_time = ctx.getElapsedTime();
|
|
239
|
-
lctx.step = dbc_step;
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
function (obj, args, ret, lctx) {
|
|
243
|
-
var pool = ret;
|
|
244
|
-
var ctx = lctx.context,
|
|
245
|
-
step = lctx.step;
|
|
246
|
-
|
|
247
|
-
if(ctx == null || step == null) { return; }
|
|
248
|
-
if(dbc_hash === 0){
|
|
249
|
-
var dbc;
|
|
250
|
-
var info = obj.connectionParameters;
|
|
251
|
-
dbc = 'postgresql://';
|
|
252
|
-
dbc += info.user || '';
|
|
253
|
-
dbc += "@";
|
|
254
|
-
dbc += info.host || '';
|
|
255
|
-
dbc += '/';
|
|
256
|
-
dbc += info.database || '';
|
|
257
|
-
dbc_hash = HashUtil.hashFromString(dbc);
|
|
258
|
-
|
|
259
|
-
DataTextAgent.DBC.add(dbc_hash, dbc);
|
|
260
|
-
DataTextAgent.METHOD.add(dbc_hash, dbc);
|
|
261
|
-
DataTextAgent.ERROR.add(dbc_hash, dbc);
|
|
262
|
-
}
|
|
263
|
-
step.hash=dbc_hash;
|
|
264
|
-
step.elapsed = ctx.getElapsedTime() - step.start_time;
|
|
265
|
-
ctx.db_opening = false;
|
|
266
|
-
|
|
267
|
-
ctx.footprint('PgSql Connecting Done');
|
|
268
|
-
|
|
269
|
-
ctx.profile.push(step);
|
|
270
|
-
|
|
271
|
-
});
|
|
272
|
-
aop.before(mod.Client.prototype, 'query', queryHook(dbc_hash, self.agent));
|
|
273
|
-
aop.before(mod.Query.prototype, 'handleError', errorDelegate());
|
|
274
|
-
|
|
275
|
-
};
|
|
276
|
-
|
|
277
257
|
var checkedSql = new IntKeyMap(2000).setMax(2000);
|
|
278
258
|
var nonLiteSql = new IntKeyMap(5000).setMax(5000);
|
|
279
259
|
var date = DateUtil.yyyymmdd();
|
package/package.json
CHANGED