whatap 0.5.0 → 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.
@@ -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
- MessageStep = require("../step/message-step");
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 queryHook = function (dbc, agent) {
35
-
36
- return function (obj, args) {
37
- var ctx = TraceContextManager.getCurrentContext();
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
- if (ctx == null || args[0] == null) { return; }
40
- if(args[0].sql == null && typeof args[0] != 'string') { return; }
38
+ Logger.initPrint("MariaObserver");
41
39
 
42
- var dbc_step = new DBCStep();
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
- dbc_step.hash = dbc_hash;
49
- dbc_step.start_time = ctx.getElapsedTime();
50
- ctx.profile.push(dbc_step);
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
- var sql_step = new SqlStepX();
53
- sql_step.start_time = ctx.getElapsedTime();
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
- ctx.footprint('Maria Query Start');
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
- ctx.sql_count++;
54
+ var _handleError = function (ctx, sql_step, err) {
55
+ sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
59
56
 
60
- var sql = args.length > 0 ? args[0] : undefined,
61
- psql = null;
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
- if(typeof sql !== 'string') {
64
- sql = args[0].sql || undefined;
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
- if (typeof sql === 'string' && sql.length > 0) {
68
- try {
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
- if(psql != null) {
79
- sql_step.hash = psql.sql;
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
- var lastCallback = false;
73
+ const connection = await original.apply(this, args);
74
+ wrapConnectionMethods(connection, agent);
109
75
 
110
- function queryCallback(obj, args) {
111
- if (ctx == null) { return; }
112
- TraceContextManager.resume(ctx._id);
76
+ ctx.footprint('Maria Connecting Done');
77
+ ctx.db_opening = false;
113
78
 
114
- if(args[0]) {
115
- try{
116
- if (conf.trace_sql_error_stack && conf.trace_sql_error_depth) {
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
- var errorStack = args[0].stack.split("\n");
120
- if (errorStack.length > traceDepth) {
121
- errorStack = errorStack.slice(0, traceDepth + 1);
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
- sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
147
- ctx.sql_time += sql_step.elapsed;
148
-
149
- // if(conf.getProperty('profile_sql_resource_enabled', false)){
150
- // sql_step.start_cpu = ResourceProfile.getCPUTime();
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
- if (args[1] != null && psql != null && psql.type === 'U') {
173
- sql_step.updated = args[1].affectedRows || 0;
174
- //StatSql.addUpdate(dbc_hash, psql.sql, sql_step.updated);
175
- }
94
+ return connectionPromise.then(connection => {
95
+ shimmer.wrap(connection, 'query', createQueryHook(agent));
96
+ return connection;
97
+ });
176
98
  }
99
+ }
100
+ }
177
101
 
178
- lastCallback = agent.aop.functionHook(args, -1, queryCallback);
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
- if(lastCallback === false && args.length>0 && args[0]._callback){
181
- agent.aop.both(args[0], '_callback', queryCallback);
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
- var toParamBytes = function(p, crc) {
187
- if(p == null || p.length === 0) {
188
- return null;
189
- }
190
- try{
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
- var errorDelegate = function () {
198
- return function (obj, args) {
199
- var ctx = TraceContextManager.getCurrentContext();
200
- if(ctx == null) { return; }
132
+ ctx.db_opening = true;
133
+ ctx.footprint('Maria Connecting Start');
201
134
 
202
- var laststep = ctx.profile.getLastSteps(1);
203
- if(laststep == null || laststep.length === 0) { return; }
135
+ const dbc_step = new DBCStep();
136
+ ctx.footprint('Maria Connecting Done');
137
+ ctx.db_opening = false;
204
138
 
205
- var step = laststep[0];
206
- if(!args[0].fatal) {
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
- try{
212
- if(args[0].fatal) {
213
- // Connection Error
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
- MariaObserver.prototype.inject = function (mod, moduleName) {
234
- if (mod.__whatap_observe__) {
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
- if (conf.sql_enabled === false) {
243
- return;
244
- }
149
+ var sql = args.length > 0 ? args[0] : undefined,
150
+ psql = null;
245
151
 
246
- var dbc_hash = 0;
247
- var dbc = 'maria://';
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
- var dbc_step = new DBCStep();
258
- dbc_step.start_time = ctx.getElapsedTime();
259
- lctx.step = dbc_step;
260
- },
261
- function (obj, args, ret, lctx) {
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
- ret.then(connection => {
279
- aop.both(connection, 'query', queryHook(dbc, self.agent), function (_obj, _args, _ret, _lctx) {
280
- var ctx = _lctx.context;
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
- TraceContextManager.resume(ctx);
307
- ctx.footprint('Maria Connecting Done');
308
- ctx.db_opening = false;
309
- step.hash = dbc_hash;
310
- });
311
-
312
-
313
- var dbc_pool_hash = 0;
314
- aop.after(mod, ['createPool', 'createPoolCluster'], function (obj, args, ret) {
315
- if (dbc_pool_hash == 0) {
316
- if (args.length > 0) {
317
- var info = args[0];
318
- dbc += info.user || '';
319
- dbc += "@";
320
- dbc += info.host || '';
321
- dbc += '/';
322
- dbc += info.database || '';
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
- aop.after(ret, 'getConnection', function (_obj, _args, _ret, _lctx) {
327
- _ret.then(connection => {
328
- aop.both(connection, 'query', queryHook(dbc, self.agent), function (__obj, __args, __ret, __lctx) {
329
- var ctx = __lctx.context;
330
- TraceContextManager.resume(ctx);
331
- });
332
- aop.both(connection, 'execute', queryHook(dbc, self.agent), function (__obj, __args, __ret, __lctx) {
333
- var ctx = __lctx.context;
334
- TraceContextManager.resume(ctx);
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
- var errorStackString = errorStack.join("\n");
105
- var error_stack_step = new MessageStep();
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, step.hash); /*long*/
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, step.hash); /*long*/
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, step.hash); /*long*/
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
- var errorStackString = errorStack.join("\n");
130
- var error_stack_step = new MessageStep();
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, step.hash); /*long*/
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, step.hash); /*long*/
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, step.hash); /*long*/
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
  }