whatap 0.5.2 → 0.5.4

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.
@@ -110,8 +110,10 @@ var ConfigDefault = {
110
110
  "trace_sampling_enabled": bool("trace_sampling_enabled", true),
111
111
  "trace_sampling_tps": bool("trace_sampling_tps", 1000),
112
112
 
113
- "profile_error_sql_time_max": num("profile_error_sql_time_max", 30000),
114
113
  "profile_error_step_enabled": bool('profile_error_step_enabled', true),
114
+ "profile_error_sql_time_max": num("profile_error_sql_time_max", 30000),
115
+ "profile_error_sql_fetch_max": num("profile_error_sql_fetch_max", 10000),
116
+ "profile_error_httpc_time_max": num("profile_error_httpc_time_max", 10000),
115
117
  "hook_direct_patch_classes": "",
116
118
 
117
119
  "log_rotation_enabled": bool('log_rotation_enabled',true),
@@ -266,6 +268,7 @@ var ConfigDefault = {
266
268
  "grpc_profile_ignore_method": bool("grpc_profile_ignore_method", true),
267
269
 
268
270
  "oname_port_postfix_enabled": bool("oname_port_postfix_enabled", false),
271
+ "ignore_http_lost_connection": bool("ignore_http_lost_connection", false)
269
272
  };
270
273
 
271
274
  ConfigDefault._hook_method_ignore_prefix = ConfigDefault.hook_method_ignore_prefixes.split(',');
@@ -26,8 +26,7 @@ var CounterPack = require('../pack/counter-pack'),
26
26
  DateUtil = require('./../util/dateutil'),
27
27
  KubeClient = require('../kube/kube-client'),
28
28
  KubeUtil = require('../util/kube-util'),
29
- Logger = require('../logger'),
30
- Long = require('long');
29
+ Logger = require('../logger');
31
30
 
32
31
  function CounterManager(agent) {
33
32
  this.agent = agent;
@@ -90,11 +89,17 @@ CounterManager.prototype.process = function (tasks) {
90
89
  var ctx = enumer.nextElement();
91
90
  if (ctx.getElapsedTime() > conf.profile_max_time) {
92
91
  //TraceContextManager.end(ctx._id);
93
- var obj = TraceContextManager.resume(ctx._id);
94
- TraceContextManager.addStep("Lost Connection","", ctx);
95
- //ctx.status = 5;
96
- //ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash);
97
- TraceContextManager.endTrace(ctx);
92
+ if(conf.getProperty("ignore_http_lost_connection", false) === true){
93
+ Logger.print("WHATAP-072", "Lost Connection was ignored, " + ctx._id, false);
94
+ TraceContextManager.end(ctx._id);
95
+ ctx = null;
96
+ }else{
97
+ // var obj = TraceContextManager.resume(ctx._id);
98
+ TraceContextManager.addStep("Lost Connection","", ctx);
99
+ //ctx.status = 5;
100
+ //ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash);
101
+ TraceContextManager.endTrace(ctx);
102
+ }
98
103
  }
99
104
  }
100
105
 
@@ -40,6 +40,8 @@ var TraceContextManager = require('../trace/trace-context-manager'),
40
40
  IntKeyLinkedMap = require("../util/intkey-linkedmap");
41
41
  const ParamSecurity = require("../util/paramsecurity");
42
42
  const {Buffer} = require("buffer");
43
+ const shimmer = require('../core/shimmer');
44
+ const TraceHttpc = require('../trace/trace-httpc');
43
45
 
44
46
  var _exts=new Set([".css",".js",".png", ".htm", ".html", ".gif", ".jpg", ".css", ".txt", ".ico"]);
45
47
 
@@ -207,10 +209,6 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
207
209
  ctx.statusMessage = ctx.error_message;
208
210
  }
209
211
 
210
- var requestPath = '';
211
- if(req.route && req.route.path)
212
- requestPath = req.route.path;
213
-
214
212
  var shouldEndTransaction = shouldEndCurrentTransaction(not_found_ignore, ctx, res, req.route ? req.route.path : '');
215
213
  if (shouldEndTransaction) {
216
214
  self.__endTransaction(null, ctx, req, res);
@@ -671,110 +669,100 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
671
669
 
672
670
  if( conf.getProperty('httpc_enabled', true) === false ) { return; }
673
671
 
674
- aop.both(mod, 'request',
675
- function (obj, args, lctx) {
676
- var ctx = lctx.context;
677
- if (ctx == null || (args[0].host == null && args[0].hostname == null) ) { return; } // for axios
678
-
679
- var isHttpsRepeat = false;
680
- if(moduleName === 'https') {
681
- args[0].__isHttps = true;
672
+ shimmer.wrap(mod, 'request', function (original) {
673
+ return function wrappedRequest(options, callback) {
674
+ var ctx = TraceContextManager.getCurrentContext();
675
+ if(!ctx || (!options.host && !options.hostname)){
676
+ return original.apply(this, arguments);
682
677
  }
683
678
 
684
- if(moduleName === 'http' && args[0].__isHttps) {
685
- isHttpsRepeat = true;
679
+ var isHttpRepeat = false;
680
+ if(moduleName === 'https'){
681
+ options.__isHttps = true;
682
+ }
683
+ if(moduleName === 'http' && options.__isHttps){
684
+ isHttpRepeat = true;
686
685
  }
687
686
 
688
- if(!isHttpsRepeat) {
689
- try {
690
- if(args[0].method === 'OPTION') {
691
- return;
692
- }
693
-
694
- var dataConsumption = false;
695
-
696
- if(args.length > 0) {
697
- var info = args[0];
698
-
699
- interTxTraceAutoOn(ctx);
700
-
701
- if(conf.mtrace_enabled){
702
- if(info.headers){
703
- info.headers['x-wtap-po']=transferPOID(ctx);
704
- }else{
705
- info.headers={
706
- 'x-wtap-po': transferPOID(ctx)
707
- };
708
- }
709
- if(conf.stat_mtrace_enabled){
710
- info.headers[conf._trace_mtrace_spec_key1]=transferSPEC_URL(ctx);
711
- }
712
- if(conf.mtid_mtrace_enabled && ctx.mtid.isZero()===false){
713
- info.headers[conf._trace_mtrace_caller_key]=transferMTID_CALLERTX(ctx);
714
- }
687
+ var step = new HttpStepX();
688
+ step.start_time = ctx.getElapsedTime();
715
689
 
690
+ if(!isHttpRepeat){
691
+ if(options.method === 'OPTION'){
692
+ return original.apply(this, arguments);
693
+ }
694
+ try{
695
+ interTxTraceAutoOn(ctx);
696
+ if(conf.getProperty('mtrace_enabled', false)){
697
+ if(options.headers){
698
+ options.headers['x-wtap-po'] = transferPOID(ctx);
699
+ }else{
700
+ options.headers = {'x-wtap-po': transferPOID(ctx)};
701
+ }
702
+ if(conf.stat_mtrace_enabled){
703
+ options.headers[conf._trace_mtrace_spec_key1]=transferSPEC_URL(ctx);
704
+ }
705
+ if(conf.mtid_mtrace_enabled && ctx.mtid.isZero()===false){
706
+ options.headers[conf._trace_mtrace_caller_key]=transferMTID_CALLERTX(ctx);
716
707
  }
717
- ctx.httpc_url = info.path || '/';
718
- ctx.httpc_host = info.host || info.hostname || '';
719
- ctx.httpc_port = info.port || -1;
720
708
  }
709
+
710
+ ctx.httpc_url = options.path || '/';
711
+ ctx.httpc_host = options.host || options.hostname || '';
712
+ ctx.httpc_port = options.port || -1;
713
+
721
714
  ctx.footprint('Http Call Start');
722
715
 
723
716
  if (ctx.httpc_port < 0) { ctx.httpc_port = 80 };
724
-
725
- } catch(e) {
726
- return Logger.printError('WHATAP-852', 'Http Repeat ', e, true);
717
+ }catch (e) {
718
+ Logger.printError('WHATAP-852', 'Http Repeat ', e, true);
719
+ return original.apply(this, arguments);
727
720
  }
721
+ }else{
722
+ return original.apply(this, arguments);
723
+ }
728
724
 
729
- aop.functionHook(args, -1, function(obj, args) {
730
- if(TraceContextManager.resume(ctx._id) == null) { return; }
725
+ var wrappedCallback;
726
+ if (typeof callback === 'function') {
727
+ wrappedCallback = function(response) {
728
+ if (TraceContextManager.resume(ctx._id) === null) {
729
+ return callback.apply(this, arguments);
730
+ }
731
731
 
732
- var res = args[0];
733
- aop.before(res, ['on', 'addListener'], function(obj, args) {
734
- if(!dataConsumption && args[0] === 'data') {
735
- dataConsumption = true;
732
+ response.on('end', function() {
733
+ step.elapsed = ctx.getElapsedTime() - step.start_time;
734
+ step.url = HashUtil.hashFromString(ctx.httpc_url);
735
+ DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url);
736
+ step.host = HashUtil.hashFromString(ctx.httpc_host);
737
+ DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host);
738
+ step.port = ctx.httpc_port;
739
+
740
+ if (response.statusCode >= 400 && transaction_status_error_enable) {
741
+ step.error = StatError.addError(response.statusCode, response.statusMessage,
742
+ ctx.service_hash, TextTypes.HTTPC_URL, step.url);
743
+ if (ctx.error.isZero()) {
744
+ ctx.error = step.error;
745
+ ctx.statusCode = response.statusCode;
746
+ ctx.statusMessage = response.statusMessage;
747
+ }
736
748
  }
737
- });
738
- aop.before(res, 'pipe', function() {
739
- dataConsumption = true;
740
- });
741
- aop.before(res, 'resume', function() {
742
- dataConsumption = true;
749
+
750
+ ctx.active_httpc_hash = step.url;
751
+ ctx.profile.push(step);
752
+ endHttpc(ctx, step);
743
753
  });
744
754
 
745
- if (dataConsumption) { return; }
746
- // endHttpc(ctx, step);
747
- });
748
- }
749
- },
750
- function (obj, args, ret, lctx) {
751
- if(moduleName === 'http' && args[0].__isHttps) {
752
- return;
755
+ return callback.apply(this, arguments);
756
+ };
753
757
  }
754
758
 
755
- var ctx = lctx.context;
756
- if (ctx == null || ( args[0].host == null && args[0].hostname == null)) { return; }
757
- var is_ignore_error = false;
758
-
759
- ret.on('response', function(response){
760
- var statusCode = response.statusCode;
761
- if(transaction_status_error_enable && statusCode >= 400){
762
- if (step.error.isZero()) {
763
- step.error = StatError.addError(statusCode, response.statusMessage , ctx.service_hash,
764
- TextTypes.HTTPC_URL, step.url);
765
- if (ctx.error.isZero()) {
766
- ctx.error = step.error;
767
- ctx.statusCode = statusCode;
768
- ctx.statusMessage = response.statusMessage;
769
- }
770
- }
771
- }
772
- })
773
- ret.on('error', function(err) {
774
- if (TraceContextManager.resume(ctx._id) == null) { return; }
759
+ var req = original.apply(this, [options, wrappedCallback]);
760
+
761
+ req.on('error', function (err) {
762
+ if (TraceContextManager.resume(ctx._id) === null) { return; }
775
763
  ctx.is_httpc_error = true;
776
764
 
777
- if (transaction_status_error_enable && step.error.isZero() && !is_ignore_error) {
765
+ if (transaction_status_error_enable && step.error.isZero()) {
778
766
  step.error = StatError.addError(err.code, err.message, ctx.service_hash,
779
767
  TextTypes.HTTPC_URL, step.url);
780
768
  if (ctx.error.isZero()) {
@@ -787,63 +775,45 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
787
775
  endHttpc(ctx, step);
788
776
  });
789
777
 
790
- var step = new HttpStepX();
791
- step.start_time = ctx.getElapsedTime();
792
- step.url = HashUtil.hashFromString(ctx.httpc_url);
793
- DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url);
794
- step.host = HashUtil.hashFromString(ctx.httpc_host);
795
- DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host);
796
- step.port = ctx.httpc_port;
797
-
798
- aop.before(ret, 'write', function (obj, args) {
799
- if(conf.profile_httpc_parameter_enabled == true) {
800
- if(args.length == 1) {
801
- var step = new MessageStep();
802
- step.hash = HashUtil.hashFromString("HTTPC-REQUEST-BODY");
803
- step.start_time = ctx.getElapsedTime();
804
- step.desc = args[0];
805
- DataTextAgent.MESSAGE.add(step.hash, "HTTPC-REQUEST-BODY");
806
- ctx.profile.push(step);
778
+ shimmer.wrap(req, 'write', function (original) {
779
+ return function wrappedWrite() {
780
+ try {
781
+ if (conf.getProperty('profile_httpc_parameter_enabled', true)) {
782
+ if (arguments && arguments[0]) {
783
+ var bodyData;
784
+
785
+ if (typeof arguments[0] === 'object' && !(arguments[0] instanceof Buffer)) {
786
+ bodyData = JSON.stringify(arguments[0]);
787
+ }
788
+ if (arguments[0] instanceof Buffer) {
789
+ bodyData = arguments[0].toString('utf8');
790
+ }
791
+ if(bodyData){
792
+ var step = new MessageStep();
793
+ step.hash = HashUtil.hashFromString("HTTPC-REQUEST-BODY");
794
+ step.start_time = ctx.getElapsedTime();
795
+ step.desc = bodyData;
796
+ DataTextAgent.MESSAGE.add(step.hash, "HTTPC-REQUEST-BODY");
797
+ ctx.profile.push(step);
798
+ }
799
+ }
800
+ }
801
+ } catch (e) {
802
+ Logger.printError('WHATAP-615', 'HTTP Write hook failed', e, false);
807
803
  }
804
+ return original.apply(this, arguments);
808
805
  }
809
806
  });
810
807
 
811
- aop.before(ret, 'end', function (obj, args) {
812
- ctx.active_httpc_hash = step.url;
813
- ctx.profile.push(step);
814
- });
815
-
816
- ret.on('socket', function(socket) {
817
- // socket reuse chk
818
- if(conf.setSocketChk(socket) == false) {
819
- aop.before(socket, 'end', function (obj, args) {
820
- if(ctx == null) { return; }
821
- TraceContextManager.resume(ctx._id);
822
- endHttpc(ctx, step);
823
- });
824
-
825
- socket.on('timeout', function () {
826
- if (TraceContextManager.resume(ctx._id) == null) { return; }
827
- is_ignore_error = true;
828
- // if (step.error.isZero()) {
829
- // var msgObj = { 'class': 'Timeout', 'msg': 'Timeout' };
830
- // step.error = StatError.addError('Timeout','Timeout', ctx.service_hash);
831
- // if (transaction_status_error_enable && ctx.error.isZero()) {
832
- // ctx.error = step.error;
833
- // ctx.statusCode = 'Timeout';
834
- // ctx.statusMessage = 'Timeout';
835
- // }
836
- // }
837
- // endHttpc(ctx, step);
838
- });
839
- }
840
- });
841
- });
808
+ return req;
809
+ }
810
+ });
842
811
 
843
812
  function endHttpc(ctx, step) {
844
813
  if(ctx == null || step == null) { return; }
845
814
 
846
815
  step.elapsed = ctx.getElapsedTime() - step.start_time;
816
+ TraceHttpc.isSlowHttpc(ctx, step);
847
817
 
848
818
  ctx.httpc_count++;
849
819
  ctx.httpc_time += step.elapsed;
@@ -23,7 +23,8 @@ 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
- shimmer = require('../core/shimmer');
26
+ shimmer = require('../core/shimmer'),
27
+ TraceSQL = require('../trace/trace-sql');
27
28
 
28
29
  var MariaObserver = function (agent) {
29
30
  this.agent = agent;
@@ -46,6 +47,7 @@ MariaObserver.prototype.inject = function (mod, moduleName) {
46
47
 
47
48
  var _finishQuery = function (ctx, sql_step) {
48
49
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
50
+ TraceSQL.isSlowSQL(ctx);
49
51
 
50
52
  MeterSql.add(sql_step.hash, sql_step.elapsed, false);
51
53
  StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, false, 0);
@@ -53,6 +55,7 @@ var _finishQuery = function (ctx, sql_step) {
53
55
 
54
56
  var _handleError = function (ctx, sql_step, err) {
55
57
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
58
+ TraceSQL.isSlowSQL(ctx);
56
59
 
57
60
  MeterSql.add(sql_step.hash, sql_step.elapsed, false);
58
61
  StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0);
@@ -192,9 +195,23 @@ function createQueryHook(agent) {
192
195
  }
193
196
 
194
197
  const result = original.apply(this, args);
195
- // return result;
198
+
196
199
  return result.then(res => {
197
- _finishQuery(ctx, sql_step);
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);
198
215
  return res;
199
216
  }).catch(err => {
200
217
  _handleError(ctx, sql_step, err)
@@ -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");
@@ -117,27 +118,25 @@ MssqlObserver.prototype.inject = function (mod, modName) {
117
118
  }
118
119
 
119
120
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
121
+ TraceSQL.isSlowSQL(ctx);
120
122
 
121
123
  MeterSql.add(dbc_hash, sql_step.elapsed, args[0] != null);
122
124
  StatSql.addSqlTime(ctx.service_hash, sql_step.dbc,
123
125
  sql_step.hash, sql_step.elapsed, args[0] != null, 0);
124
126
 
125
- // if(conf.getProperty('profile_sql_resource_enabled', false)){
126
- // sql_step.start_cpu = ResourceProfile.getCPUTime();
127
- // sql_step.start_mem = ResourceProfile.getUsedHeapSize();
128
- // }
129
-
130
127
  if(psql && psql.type == 'S') {
131
128
  var result_step = new ResultSetStep();
132
129
  result_step.dbc = sql_step.dbc;
133
130
  result_step.sqlhash = sql_step.hash;
134
131
  try {
135
- result_step.fetch = args[1].recordset.length;
132
+ result_step.fetch = args[1][0].length;
136
133
  } catch(e) {
137
134
  }
138
135
  ctx.profile.push(result_step);
139
136
  MeterSql.addFetch(dbc_hash, result_step.fetch, 0);
140
137
  StatSql.addFetch(dbc_hash, result_step.sqlhash, result_step.fetch, 0);
138
+
139
+ TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
141
140
  } else if(psql && psql.type == 'U') {
142
141
 
143
142
  }
@@ -22,8 +22,8 @@ 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
- // const ResourceProfile = require('../util/resourceprofile');
25
+ Buffer = require('buffer').Buffer,
26
+ TraceSQL = require('../trace/trace-sql');
27
27
 
28
28
  var MysqlObserver = function (agent) {
29
29
  this.agent = agent;
@@ -162,6 +162,8 @@ var queryHook = function (dbc, agent) {
162
162
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
163
163
  ctx.sql_time += sql_step.elapsed;
164
164
 
165
+ TraceSQL.isSlowSQL(ctx);
166
+
165
167
  // if(conf.getProperty('profile_sql_resource_enabled', false)){
166
168
  // sql_step.start_cpu = ResourceProfile.getCPUTime();
167
169
  // sql_step.start_mem = ResourceProfile.getUsedHeapSize();
@@ -183,6 +185,8 @@ var queryHook = function (dbc, agent) {
183
185
  ctx.profile.push(result_step);
184
186
  MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
185
187
  StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
188
+
189
+ TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
186
190
  }
187
191
 
188
192
  if (args[1] != null && psql != null && psql.type === 'U') {
@@ -20,8 +20,10 @@ var TraceContextManager = require('../trace/trace-context-manager'),
20
20
  ParamSecurity = require('../util/paramsecurity'),
21
21
  Logger = require('../logger'),
22
22
  Buffer = require('buffer').Buffer,
23
- DateUtil = require('../util/dateutil');
23
+ DateUtil = require('../util/dateutil'),
24
+ TraceSQL = require('../trace/trace-sql');
24
25
  const shimmer = require('../core/shimmer');
26
+ const ResultSetStep = require("../step/resultset-step");
25
27
 
26
28
  var PgSqlObserver = function (agent) {
27
29
  this.agent = agent;
@@ -170,11 +172,23 @@ PgSqlObserver.prototype.inject = function (mod, moduleName) {
170
172
  }
171
173
 
172
174
  try {
173
- // SQL 실행
174
175
  const result = original.apply(this, arguments);
175
176
 
176
177
  if (result && result.then) {
177
178
  return result.then(res => {
179
+ if(res.command && res.command === 'SELECT'){
180
+ var result_step = new ResultSetStep();
181
+ result_step.start_time = ctx.getElapsedTime();
182
+ result_step.elapsed = 0;
183
+ result_step.fetch = res.rowCount;
184
+ result_step.sqlhash = psql.sql;
185
+ result_step.dbc = dbc_hash;
186
+ ctx.profile.push(result_step);
187
+ MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
188
+ StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
189
+
190
+ TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx);
191
+ }
178
192
  self._finishQuery(ctx, sql_step);
179
193
  return res;
180
194
  }).catch(err => {
@@ -211,25 +225,11 @@ PgSqlObserver.prototype.inject = function (mod, moduleName) {
211
225
  }
212
226
  };
213
227
  });
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
228
  };
229
229
 
230
- // 쿼리 완료 처리
231
230
  PgSqlObserver.prototype._finishQuery = function (ctx, sql_step) {
232
231
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
232
+ TraceSQL.isSlowSQL(ctx);
233
233
 
234
234
  MeterSql.add(sql_step.hash, sql_step.elapsed, false);
235
235
  StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, false, 0);
@@ -237,8 +237,8 @@ PgSqlObserver.prototype._finishQuery = function (ctx, sql_step) {
237
237
 
238
238
  PgSqlObserver.prototype._handleError = function (ctx, sql_step, err) {
239
239
  sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time;
240
+ TraceSQL.isSlowSQL(ctx);
240
241
 
241
- // Logger.printError('WHATAP-192', 'PGSQL Query error.', err);
242
242
  MeterSql.add(sql_step.hash, sql_step.elapsed, false);
243
243
  StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0);
244
244
  };
@@ -0,0 +1,26 @@
1
+ const HttpStepX = require('../step/http-stepx'),
2
+ conf = require('../conf/configure'),
3
+ StatError= require('../stat/stat-error'),
4
+ TextTypes= require("../lang/text-types");
5
+
6
+ var TraceHttpc = function () {}
7
+
8
+ TraceHttpc.prototype.hasHttpStepX = function (buffer) {
9
+ if (!Array.isArray(buffer)) {
10
+ return [];
11
+ }
12
+
13
+ return buffer.filter(item => item instanceof HttpStepX);
14
+ }
15
+
16
+ TraceHttpc.prototype.isSlowHttpc = function (ctx, httpc_step) {
17
+ if(!ctx.profile.buffer)
18
+ return;
19
+ var profile_error_httpc_time_max = conf.getProperty('profile_error_httpc_time_max', 10000);
20
+
21
+ if(httpc_step.elapsed && (httpc_step.elapsed > profile_error_httpc_time_max)){
22
+ httpc_step.error = StatError.addError('SLOW_HTTPC', 'SLOW HTTPC', ctx.service_hash, TextTypes.HTTPC_URL, null);
23
+ }
24
+ }
25
+
26
+ module.exports = new TraceHttpc();
@@ -0,0 +1,45 @@
1
+ const SqlStepX = require('../step/sql-stepx'),
2
+ conf = require('../conf/configure'),
3
+ StatError = require('../stat/stat-error'),
4
+ TextTypes = require("../lang/text-types");
5
+
6
+ var TraceSql = function () {}
7
+
8
+ TraceSql.prototype.hasSqlStepX = function (buffer) {
9
+ if (!Array.isArray(buffer)) {
10
+ return [];
11
+ }
12
+
13
+ return buffer.filter(item => item instanceof SqlStepX);
14
+ }
15
+
16
+ TraceSql.prototype.isSlowSQL = function (ctx) {
17
+ if(!ctx.profile.buffer)
18
+ return;
19
+
20
+ var profile_error_sql_time_max = conf.getProperty('profile_error_sql_time_max', 30000);
21
+ var sqlStepX = this.hasSqlStepX(ctx.profile.buffer);
22
+ var slow_sql_step = sqlStepX.find(step => step.elapsed > profile_error_sql_time_max);
23
+ if(slow_sql_step){
24
+ slow_sql_step.error = StatError.addError('SLOW_SQL', 'SLOW SQL', ctx.service_hash, TextTypes.SQL, null);
25
+ if(ctx.error.isZero()){
26
+ ctx.error = slow_sql_step.error;
27
+ }
28
+ }
29
+ return;
30
+ }
31
+
32
+ TraceSql.prototype.isTooManyRecords = function (sql_step, rs_count, ctx) {
33
+ if(!ctx.profile.buffer)
34
+ return;
35
+
36
+ var profile_error_sql_fetch_max = conf.getProperty('profile_error_sql_fetch_max', 10000);
37
+ if(rs_count && rs_count > profile_error_sql_fetch_max){
38
+ sql_step.error = StatError.addError('TOO_MANY_RECORDS', 'Too many records', ctx.service_hash, TextTypes.SQL, null)
39
+ if(ctx.error.isZero()){
40
+ ctx.error = sql_step.error;
41
+ }
42
+ }
43
+ }
44
+
45
+ module.exports = new TraceSql();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "0.5.2",
5
- "releaseDate": "20241017",
4
+ "version": "0.5.4",
5
+ "releaseDate": "20241113",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},