whatap 0.5.26 → 1.0.0

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.
Files changed (196) hide show
  1. package/agent/darwin/arm64/whatap_nodejs +0 -0
  2. package/agent/linux/amd64/whatap_nodejs +0 -0
  3. package/agent/linux/arm64/whatap_nodejs +0 -0
  4. package/build.txt +4 -0
  5. package/lib/conf/config-default.js +3 -10
  6. package/lib/conf/configure.js +349 -369
  7. package/lib/conf/license.js +1 -1
  8. package/lib/control/packagectr-helper.js +3 -34
  9. package/lib/core/agent.js +882 -176
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/shimmer.js +36 -82
  12. package/lib/counter/counter-manager.js +8 -79
  13. package/lib/counter/task/activetransaction.js +17 -68
  14. package/lib/io/data-inputx.js +3 -13
  15. package/lib/io/data-outputx.js +206 -268
  16. package/lib/logger.js +6 -6
  17. package/lib/net/security-master.js +20 -139
  18. package/lib/observers/apollo-server-observer.js +27 -33
  19. package/lib/observers/global-observer.js +80 -155
  20. package/lib/observers/http-observer.js +236 -666
  21. package/lib/observers/ioredis-observer.js +294 -0
  22. package/lib/observers/maria-observer.js +362 -204
  23. package/lib/observers/mongodb-observer.js +226 -169
  24. package/lib/observers/mongoose-observer.js +323 -518
  25. package/lib/observers/mssql-observer.js +418 -177
  26. package/lib/observers/mysql-observer.js +449 -342
  27. package/lib/observers/mysql2-observer.js +358 -396
  28. package/lib/observers/oracle-observer.js +384 -559
  29. package/lib/observers/pgsql-observer.js +489 -231
  30. package/lib/observers/prisma-observer.js +92 -303
  31. package/lib/observers/process-observer.js +35 -79
  32. package/lib/observers/redis-observer.js +331 -166
  33. package/lib/observers/socket.io-observer.js +187 -226
  34. package/lib/observers/websocket-observer.js +301 -175
  35. package/lib/pack/counter-pack.js +0 -3
  36. package/lib/pack/log-sink-pack.js +52 -14
  37. package/lib/pack/tagcount-pack.js +4 -4
  38. package/lib/{counter/task → system}/gc-action.js +74 -27
  39. package/lib/trace/trace-context-manager.js +25 -113
  40. package/lib/trace/trace-context.js +7 -21
  41. package/lib/trace/trace-httpc.js +11 -17
  42. package/lib/trace/trace-sql.js +21 -29
  43. package/lib/udp/async_sender.js +119 -0
  44. package/lib/udp/index.js +17 -0
  45. package/lib/udp/packet_enum.js +52 -0
  46. package/lib/udp/packet_queue.js +69 -0
  47. package/lib/udp/packet_type_enum.js +33 -0
  48. package/lib/udp/param_def.js +72 -0
  49. package/lib/udp/udp_session.js +336 -0
  50. package/lib/util/escape-literal-sql.js +5 -5
  51. package/lib/util/hashutil.js +18 -18
  52. package/lib/util/keygen.js +3 -0
  53. package/lib/util/linkedset.js +2 -1
  54. package/lib/util/nodeutil.js +1 -2
  55. package/lib/util/sql-util.js +178 -0
  56. package/lib/util/trace-helper.js +91 -0
  57. package/lib/util/transfer.js +58 -0
  58. package/lib/value/map-value.js +2 -3
  59. package/package.json +5 -10
  60. package/lib/conf/conf-sys-mon.js +0 -101
  61. package/lib/control/cmd-config.js +0 -24
  62. package/lib/control/control-handler.js +0 -367
  63. package/lib/core/request-agent.js +0 -27
  64. package/lib/counter/meter/meter-activex.js +0 -67
  65. package/lib/counter/meter/meter-httpc.js +0 -57
  66. package/lib/counter/meter/meter-resource.js +0 -9
  67. package/lib/counter/meter/meter-service.js +0 -168
  68. package/lib/counter/meter/meter-socket.io.js +0 -51
  69. package/lib/counter/meter/meter-sql.js +0 -71
  70. package/lib/counter/meter/meter-users.js +0 -58
  71. package/lib/counter/meter.js +0 -183
  72. package/lib/counter/task/agentinfo.js +0 -107
  73. package/lib/counter/task/gcstat.js +0 -34
  74. package/lib/counter/task/heapmem.js +0 -25
  75. package/lib/counter/task/httpc.js +0 -76
  76. package/lib/counter/task/metering-info.js +0 -125
  77. package/lib/counter/task/proc-cpu.js +0 -29
  78. package/lib/counter/task/realtimeuser.js +0 -31
  79. package/lib/counter/task/res/systemECSTask.js +0 -39
  80. package/lib/counter/task/res/systemKubeTask.js +0 -53
  81. package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
  82. package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
  83. package/lib/counter/task/res-sys-cpu.js +0 -62
  84. package/lib/counter/task/service.js +0 -202
  85. package/lib/counter/task/socketio.js +0 -30
  86. package/lib/counter/task/sql.js +0 -105
  87. package/lib/counter/task/systemperf.js +0 -43
  88. package/lib/data/datapack-sender.js +0 -289
  89. package/lib/data/dataprofile-agent.js +0 -162
  90. package/lib/data/datatext-agent.js +0 -135
  91. package/lib/data/event-level.js +0 -15
  92. package/lib/data/test.js +0 -49
  93. package/lib/data/zipprofile.js +0 -197
  94. package/lib/env/constants.js +0 -21
  95. package/lib/error/error-handler.js +0 -437
  96. package/lib/kube/kube-client.js +0 -144
  97. package/lib/lang/text-types.js +0 -58
  98. package/lib/logsink/line-log-util.js +0 -87
  99. package/lib/logsink/line-log.js +0 -12
  100. package/lib/logsink/log-sender.js +0 -78
  101. package/lib/logsink/log-tracer.js +0 -40
  102. package/lib/logsink/sender-util.js +0 -56
  103. package/lib/logsink/zip/zip-send.js +0 -177
  104. package/lib/net/netflag.js +0 -55
  105. package/lib/net/receiver.js +0 -66
  106. package/lib/net/sender.js +0 -141
  107. package/lib/net/tcp-return.js +0 -18
  108. package/lib/net/tcp-session.js +0 -286
  109. package/lib/net/tcpreq-client-proxy.js +0 -70
  110. package/lib/net/tcprequest-mgr.js +0 -58
  111. package/lib/observers/cluster-observer.js +0 -22
  112. package/lib/observers/express-observer.js +0 -215
  113. package/lib/observers/file-observer.js +0 -184
  114. package/lib/observers/grpc-observer.js +0 -336
  115. package/lib/observers/memcached-observer.js +0 -56
  116. package/lib/observers/mongo-observer.js +0 -317
  117. package/lib/observers/net-observer.js +0 -77
  118. package/lib/observers/promise-observer.js +0 -31
  119. package/lib/observers/schedule-observer.js +0 -67
  120. package/lib/observers/stream-observer.js +0 -19
  121. package/lib/observers/thrift-observer.js +0 -197
  122. package/lib/pack/activestack-pack.js +0 -55
  123. package/lib/pack/apenum.js +0 -8
  124. package/lib/pack/errorsnap-pack.js +0 -69
  125. package/lib/pack/event-pack.js +0 -54
  126. package/lib/pack/hitmap-pack.js +0 -63
  127. package/lib/pack/hitmap-pack1.js +0 -152
  128. package/lib/pack/netstat.js +0 -15
  129. package/lib/pack/otype.js +0 -7
  130. package/lib/pack/profile-pack.js +0 -49
  131. package/lib/pack/realtimeuser-pack.js +0 -41
  132. package/lib/pack/stat-general-pack.js +0 -96
  133. package/lib/pack/staterror-pack.js +0 -120
  134. package/lib/pack/stathttpc-pack.js +0 -66
  135. package/lib/pack/stathttpc-rec.js +0 -78
  136. package/lib/pack/statremote-pack.js +0 -46
  137. package/lib/pack/statservice-pack.js +0 -63
  138. package/lib/pack/statservice-pack1.js +0 -88
  139. package/lib/pack/statservice-rec.js +0 -292
  140. package/lib/pack/statservice-rec_dep.js +0 -151
  141. package/lib/pack/statsql-pack.js +0 -69
  142. package/lib/pack/statsql-rec.js +0 -100
  143. package/lib/pack/statuseragent-pack.js +0 -44
  144. package/lib/pack/tagctr.js +0 -15
  145. package/lib/pack/text-pack.js +0 -50
  146. package/lib/pack/time-count.js +0 -25
  147. package/lib/pack/websocket.js +0 -15
  148. package/lib/pack/zip-pack.js +0 -70
  149. package/lib/pii/pii-item.js +0 -31
  150. package/lib/pii/pii-mask.js +0 -174
  151. package/lib/plugin/plugin-loadermanager.js +0 -57
  152. package/lib/plugin/plugin.js +0 -75
  153. package/lib/service/tx-record.js +0 -332
  154. package/lib/stat/stat-error.js +0 -116
  155. package/lib/stat/stat-httpc.js +0 -98
  156. package/lib/stat/stat-remote-ip.js +0 -46
  157. package/lib/stat/stat-remote-ipurl.js +0 -88
  158. package/lib/stat/stat-sql.js +0 -113
  159. package/lib/stat/stat-tranx.js +0 -58
  160. package/lib/stat/stat-tx-caller.js +0 -160
  161. package/lib/stat/stat-tx-domain.js +0 -111
  162. package/lib/stat/stat-tx-referer.js +0 -112
  163. package/lib/stat/stat-useragent.js +0 -48
  164. package/lib/stat/timingsender.js +0 -76
  165. package/lib/step/activestack-step.js +0 -38
  166. package/lib/step/dbc-step.js +0 -36
  167. package/lib/step/http-stepx.js +0 -67
  168. package/lib/step/message-step.js +0 -40
  169. package/lib/step/method-stepx.js +0 -45
  170. package/lib/step/resultset-step.js +0 -40
  171. package/lib/step/securemsg-step.js +0 -44
  172. package/lib/step/socket-step.js +0 -46
  173. package/lib/step/sql-stepx.js +0 -68
  174. package/lib/step/sqlxtype.js +0 -16
  175. package/lib/step/step.js +0 -66
  176. package/lib/step/stepenum.js +0 -54
  177. package/lib/topology/link.js +0 -63
  178. package/lib/topology/nodeinfo.js +0 -123
  179. package/lib/topology/status-detector.js +0 -111
  180. package/lib/util/anylist.js +0 -103
  181. package/lib/util/cardinality/hyperloglog.js +0 -106
  182. package/lib/util/cardinality/murmurhash.js +0 -31
  183. package/lib/util/cardinality/registerset.js +0 -75
  184. package/lib/util/errordata.js +0 -21
  185. package/lib/util/iputil_x.js +0 -527
  186. package/lib/util/kube-util.js +0 -73
  187. package/lib/util/paramsecurity.js +0 -80
  188. package/lib/util/pre-process.js +0 -13
  189. package/lib/util/process-seq.js +0 -166
  190. package/lib/util/property-util.js +0 -36
  191. package/lib/util/request-queue.js +0 -70
  192. package/lib/util/requestdouble-queue.js +0 -72
  193. package/lib/util/resourceprofile.js +0 -157
  194. package/lib/util/stop-watch.js +0 -30
  195. package/lib/util/system-util.js +0 -10
  196. package/lib/util/userid-util.js +0 -57
package/lib/logger.js CHANGED
@@ -213,23 +213,23 @@
213
213
  for (var i = 0; i < files.length; i++) {
214
214
  var stat = fs.statSync(path.join(dir, files[i]));
215
215
  if (stat.isDirectory()) {
216
- continue;
216
+ return true;
217
217
  }
218
218
  var name = files[i];
219
219
  if (name.indexOf(log_prefix) < 0) {
220
- continue;
220
+ return true;
221
221
  }
222
222
  var x = name.lastIndexOf('.');
223
223
  if (x < 0) {
224
- continue;
224
+ return true;
225
225
  }
226
226
  var date = name.substr(log_prefix.length, (x - log_prefix.length));
227
227
  if (date.length != 8) {
228
- continue;
228
+ return true;
229
229
  }
230
+ var d = DateUtil.yyyymmdd(date);
231
+ var fileUnit = DateUtil.getDateUnit(d);
230
232
  try {
231
- var d = DateUtil.yyyymmdd(date);
232
- var fileUnit = DateUtil.getDateUnit(d);
233
233
  if (nowUnit - fileUnit > conf.log_keep_days) {
234
234
  let filePath = `${dir}/${files[i]}`;
235
235
  fs.rmSync(filePath);
@@ -9,11 +9,9 @@ var DataInputX = require('./../io/data-inputx'),
9
9
  Cypher = require('./../util/cypher'),
10
10
  IPUtil = require('./../util/iputil'),
11
11
  OidUtil = require('./../util/oidutil'),
12
- ProcessSeq = require('./../util/process-seq'),
13
12
  HashUtil = require('./../util/hashutil');
14
13
 
15
14
  var cluster = require('cluster');
16
- const Configuration = require("../conf/configure");
17
15
 
18
16
  var lastOid = 0;
19
17
 
@@ -26,163 +24,46 @@ var SecurityMaster = {
26
24
  ONODE : 0,
27
25
  ONODE_NAME : null,
28
26
  OID: 0 ,
29
- run : function(cb){
27
+ decideAgentOnameOid: function() {
30
28
  var conf = require('./../conf/configure');
31
- if( this.resetLicense( conf.license )) {
32
- require('../logger').print('WHATAP-110', "[pcode=" + this.PCODE
33
- + ",SECURE_KEY=" + this.SECURE_KEY.toString('hex')
34
- + "]", false);
35
- this.getClusterId(cb);
36
- } else {
37
- if(cb) cb(new Error('Invalid license'));
38
- }
39
- },
40
- resetLicense: function(lic /* String */){
41
- try {
42
- var key = License.getKey(lic);
43
- if(key.pcode == null || key.security_key == null) {
44
- throw new Error('Invalid license');
45
- }
46
- this.PCODE = key.pcode;
47
- this.SECURE_KEY = key.security_key;
48
- this.cypher = new Cypher(this.SECURE_KEY, 0);
49
- return true;
50
- } catch(e) {
51
- require('../logger').printError('WHATAP-606', 'LicenseKey is invalid ' + lic, e, true);
52
- }
53
- return false;
54
- },
55
- updateLocalIp: function(myIp){
56
- process.env["whatap.ip"] = myIp;
57
- this.IP = 0;
58
- },
59
- decideAgentOnameOid: function(myIp) {
60
- var Configuration = require('./../conf/configure');
61
- Configuration.setProperty('whatap.ip', myIp);
29
+ const myIp = IPUtil.getIp();
30
+ conf.setProperty('whatap.ip', myIp);
62
31
 
63
32
  this.IP = IPUtil.stringToInt(myIp);
64
- var port = Configuration.getProperty("whatap.port");
33
+ var port = conf.getProperty("whatap.port");
65
34
  OidUtil.setIp(IPUtil.intToString(this.IP));
66
35
  OidUtil.setPort(port);
67
36
  OidUtil.setPid(process.pid);
68
37
  OidUtil.setHostName(require('os').hostname());
69
- //OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"));
70
- OidUtil.setType(process.env.name || Configuration.getProperty("whatap.type", "NODE"));
38
+ OidUtil.setType(process.env.name || conf.getProperty("whatap.type", "NODE"));
71
39
 
72
- var name_pattern;
73
- if(Configuration.getProperty('whatap_micro_enabled', false) === true || process.env.WHATAP_MICRO_ENABLED === "true"){
74
- name_pattern = process.env.WHATAP_NAME || "{okind}-{ip2}-{ip3}";
75
- }else if(require('cluster').isMaster){
76
- name_pattern=process.env.WHATAP_NAME || "{type}-{ip2}-{ip3}";
77
- }else{
78
- name_pattern=process.env.WHATAP_NAME || "{type}{cluster}-{ip2}-{ip3}";
79
- var cid = Configuration.getProperty('node.clusterId');
80
- OidUtil.setCluster(cid);
81
- }
40
+ this.OID = conf.getProperty("OID", 0);
41
+ this.ONAME = conf.getProperty("app_name", "");
82
42
 
83
- var okindStr= process.env.WHATAP_OKIND || Configuration.getProperty('whatap.okind');
84
- if(okindStr && okindStr.length>0){
85
- this.OKIND = HashUtil.hashFromString(okindStr);
86
- this.OKIND_NAME=okindStr;
87
- OidUtil.setOkind(okindStr);
88
- }else{
89
- this.OKIND = 0;
90
- this.OKIND_NAME=null;
43
+ this.OKIND_NAME = conf.getProperty("whatap.okind", "")
44
+ if(!this.OKIND_NAME){
45
+ this.OKIND_NAME = process.env.WHATAP_OKIND || "";
91
46
  }
92
-
93
- const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
94
- const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
95
-
96
- if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
97
- var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
98
- if(onodeStr && onodeStr.length>0){
99
- this.ONODE = HashUtil.hashFromString(onodeStr);
100
- this.ONODE_NAME=onodeStr;
101
- }else{
102
- this.ONODE = 0;
103
- this.ONODE_NAME=null;
104
- }
47
+ if(!this.OKIND_NAME){
48
+ this.OKIND_NAME = process.env.POD_NAME || ""
105
49
  }
106
-
107
- //OidUtil.setCmd(Configuration.getProperty("sun.java.command"));
108
- this.ONAME = OidUtil.mkOname(Configuration.getProperty("whatap.name", name_pattern), port);
109
- this.OID = OidUtil.mkOid(this.ONAME);
110
-
111
- if (lastOid != this.OID) {
112
- lastOid = this.OID;
113
- require('../logger').print('WHATAP-968', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
50
+ if(this.OKIND_NAME){
51
+ this.OKIND = HashUtil.hashFromString(this.OKIND_NAME);
114
52
  }
115
- },
116
- setAgentOnameOid :function (oname, myIp) {
117
- var Configuration = require('./../conf/configure');
118
- Configuration.setProperty('whatap.ip', myIp);
119
53
 
120
- this.IP = IPUtil.stringToInt(myIp);//DataInputX.toInt(IPUtil.toBytes(myIp), 0);
121
- var port = Configuration.getProperty("whatap.port");
122
- OidUtil.setIp(IPUtil.intToString(this.IP));
123
- OidUtil.setPort(port);
124
- OidUtil.setPid(process.pid);
125
- OidUtil.setHostName(require('os').hostname());
126
- if(require('cluster').isMaster){
127
- OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"));
128
- }else{
129
- OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"+ Configuration.getProperty('node.clusterId') ) );
54
+ this.ONODE_NAME = conf.getProperty("whatap.onode", "");
55
+ if(!this.ONODE_NAME){
56
+ this.ONODE_NAME = process.env.NODE_NAME || "";
130
57
  }
131
-
132
- OidUtil.setCmd(Configuration.getProperty("sun.java.command"));
133
- this.ONAME = oname;
134
- this.OID = OidUtil.mkOid(this.ONAME);
135
-
136
- var okindStr= process.env.WHATAP_OKIND || Configuration.getProperty('whatap.okind');
137
- if(okindStr && okindStr.length>0){
138
- this.OKIND = HashUtil.hashFromString(okindStr);
139
- this.OKIND_NAME=okindStr;
140
- }else{
141
- this.OKIND = 0;
142
- this.OKIND_NAME=null;
58
+ if(this.ONODE_NAME){
59
+ this.ONODE = HashUtil.hashFromString(this.ONODE_NAME);
143
60
  }
144
61
 
145
- const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
146
- const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
147
-
148
- if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
149
- var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
150
- if(onodeStr && onodeStr.length>0){
151
- this.ONODE = HashUtil.hashFromString(onodeStr);
152
- this.ONODE_NAME=onodeStr;
153
- }else{
154
- this.ONODE = 0;
155
- this.ONODE_NAME=null;
156
- }
157
- }
158
62
 
159
63
  if (lastOid != this.OID) {
160
64
  lastOid = this.OID;
161
- require('../logger').print('WHATAP-168', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
65
+ require('../logger').print('WHATAP-401', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
162
66
  }
163
- },
164
- getClusterId: function(cb){
165
- var conf = require('./../conf/configure');
166
- if(cluster.isMaster){
167
- //console.log('현재 프로젝트는 MASTER 입니다!!!!');
168
- conf.setProperty('node.clusterId', '');
169
- if(cb) cb();
170
- }else{
171
- conf.setProperty('node.clusterId', cluster.worker.id);
172
- if(cb) cb();
173
- //console.log('현재 프로젝트는 ' + cluster.worker.id + ' 입니다!!!!');
174
- /*
175
- ProcessSeq('whatap').accessAuth(function(pseq){
176
- if(!pseq){
177
- return;
178
- }
179
- var conf = require('./../conf/configure');
180
- conf.setProperty('node.clusterId', pseq);
181
- if(cb) cb();
182
- });
183
- */
184
- }
185
-
186
67
  }
187
68
  };
188
69
 
@@ -8,11 +8,9 @@ var TraceContextManager = require('../trace/trace-context-manager'),
8
8
  conf = require('../conf/configure'),
9
9
  Logger = require('../logger');
10
10
  const HashUtil = require('../util/hashutil');
11
- const DataTextAgent = require('../data/datatext-agent');
12
- const MessageStep = require('../step/message-step');
13
11
  const shimmer = require('../core/shimmer');
14
- const StatError = require("whatap/lib/stat/stat-error");
15
- const TextTypes = require("whatap/lib/lang/text-types");
12
+ const AsyncSender = require('../udp/async_sender');
13
+ const PacketTypeEnum = require('../udp/packet_type_enum');
16
14
 
17
15
  var profile_graphql_enabled = conf.getProperty('profile_graphql_enabled', true);
18
16
  var profile_graphql_variable_enabled = conf.getProperty('profile_graphql_variable_enabled', false);
@@ -45,7 +43,7 @@ function checkIgnoreOperation(ignore_operation, operation_name) {
45
43
  return true;
46
44
  }
47
45
  } catch (e) {
48
- Logger.printError('WHATAP-803', 'GraphQL checkIgnoreOperation error: ' + e, false);
46
+ Logger.printError('WHATAP-248', 'GraphQL checkIgnoreOperation error: ' + e, false);
49
47
  }
50
48
  return false;
51
49
  }
@@ -80,32 +78,25 @@ function wrapExecuteHTTPGraphQLRequest(original) {
80
78
 
81
79
  // Operation Type Step (query)
82
80
  if(body.query && body.query.trim()){
83
- var step_type = new MessageStep();
84
- step_type.hash = HashUtil.hashFromString('Type');
85
- step_type.start_time = ctx.getElapsedTime();
86
- step_type.desc = body.query.trim().startsWith('mutation') ? 'mutation' : 'query';
87
- DataTextAgent.MESSAGE.add(step_type.hash, "Type");
88
- ctx.profile.push(step_type);
81
+ const queryType = body.query.trim().startsWith('mutation') ? 'mutation' : 'query';
82
+ let typeDatas = ['Type', 'Type', queryType];
83
+ ctx.start_time = Date.now();
84
+ AsyncSender.send_packet(PacketTypeEnum.TX_MSG, ctx, typeDatas);
89
85
  }
90
86
 
91
87
  // Operation Name Step
92
88
  if(operationName){
93
- var step_operation = new MessageStep();
94
- step_operation.hash = HashUtil.hashFromString('Operation');
95
- step_operation.start_time = ctx.getElapsedTime();
96
- step_operation.desc = operationName || 'anonymous';
97
- DataTextAgent.MESSAGE.add(step_operation.hash, "Operation");
98
- ctx.profile.push(step_operation);
89
+ let operationDatas = ['Operation', 'Operation', operationName || 'anonymous'];
90
+ ctx.start_time = Date.now();
91
+ AsyncSender.send_packet(PacketTypeEnum.TX_MSG, ctx, operationDatas);
99
92
  }
100
93
 
101
94
  // Variables Step
102
95
  if (profile_graphql_variable_enabled && body.variables && Object.keys(body.variables).length > 0) {
103
- var step_variables = new MessageStep();
104
- step_variables.hash = HashUtil.hashFromString('Variables');
105
- step_variables.start_time = ctx.getElapsedTime();
106
- step_variables.desc = JSON.stringify(Object.keys(body.variables));
107
- DataTextAgent.MESSAGE.add(step_variables.hash, "Variables");
108
- ctx.profile.push(step_variables);
96
+ const variableKeys = JSON.stringify(Object.keys(body.variables));
97
+ let variableDatas = ['Variables', 'Variables', variableKeys];
98
+ ctx.start_time = Date.now();
99
+ AsyncSender.send_packet(PacketTypeEnum.TX_MSG, ctx, variableDatas);
109
100
  }
110
101
 
111
102
  const response = await original.apply(this, arguments);
@@ -116,27 +107,30 @@ function wrapExecuteHTTPGraphQLRequest(original) {
116
107
  const result = JSON.parse(response.body.string);
117
108
  if (result.errors && result.errors.length > 0) {
118
109
  const errorMessages = result.errors.map(error => error.message).join('\n');
119
- ctx.statusCode = response.status;
120
- ctx.error_message = errorMessages;
121
- ctx.error_class = 'GraphQLError';
110
+ ctx.status = response.status;
122
111
 
123
- if(ctx.error.isZero()){
124
- ctx.error = StatError.addError(response.status, errorMessages, ctx.service_hash, TextTypes.SQL, HashUtil.hashFromString(ctx.service_name));
112
+ if (response.status >= 400 && !ctx.error) {
113
+ ctx.error = 1;
114
+ let errors = ['GraphQLError', errorMessages];
115
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
125
116
  }
126
117
  }
127
118
  } catch (e) {
128
- Logger.printError('WHATAP-802', 'GraphQL error parsing failed', e, false);
119
+ Logger.printError('WHATAP-249', 'GraphQL error parsing failed', e, false);
129
120
  }
130
121
  }
131
122
 
132
123
  return response;
133
124
 
134
125
  } catch (err) {
135
- Logger.printError('WHATAP-801', 'GraphQL executeHTTPGraphQLRequest error: ' + err, false);
126
+ Logger.printError('WHATAP-250', 'GraphQL executeHTTPGraphQLRequest error: ' + err, false);
136
127
  if (ctx) {
137
- ctx.statusCode = 500;
138
- ctx.error_message = err.message;
139
- ctx.error_class = err.name || err.constructor?.name || 'UnknownError'
128
+ ctx.status = 500;
129
+ if (!ctx.error) {
130
+ ctx.error = 1;
131
+ let errors = [err.name || err.constructor?.name || 'UnknownError', err.message];
132
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
133
+ }
140
134
  }
141
135
  return original.apply(this, arguments);
142
136
  }
@@ -4,20 +4,18 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
7
- var TraceContextManager = require('../trace/trace-context-manager'),
8
- Logger = require('../logger');
7
+ var TraceContextManager = require('../trace/trace-context-manager');
9
8
 
10
- var HttpStepX = require('../step/http-stepx');
11
9
  const Hexa32 = require("../util/hexa32");
12
10
  const SecurityMaster = require("../net/security-master");
13
11
  const conf = require("../conf/configure");
14
12
  const KeyGen = require("../util/keygen");
15
- const HashUtil = require("../util/hashutil");
16
- const DataTextAgent = require("../data/datatext-agent");
13
+ const TraceHelper = require('../util/trace-helper');
17
14
  const shimmer = require('../core/shimmer');
18
- const StatError = require("../stat/stat-error");
19
- const TextTypes = require("../lang/text-types");
20
- const URLPatternDetector = require('../trace/serviceurl-pattern-detector').Detector;
15
+ const AsyncSender = require('../udp/async_sender');
16
+ const { PacketTypeEnum } = require("../../lib/udp");
17
+ const Transfer = require('../util/transfer');
18
+ const TraceHttpc = require('../trace/trace-httpc');
21
19
 
22
20
  var GlobalObserver = function (agent) {
23
21
  this.agent = agent;
@@ -32,30 +30,28 @@ conf.on('transaction_status_error_enable', function (newProps) {
32
30
  GlobalObserver.prototype.inject = function (mod, moduleName) {
33
31
  var self = this;
34
32
 
35
- ['setTimeout', 'setInterval', 'setImmediate'].forEach(function (funcName) {
36
- self.agent.aop.before(mod, funcName, function (obj, args) {
37
- if(args[args.length - 1] === 'whatap') { return; }
38
-
39
- var cached_id = TraceContextManager.getCurrentId();
40
- self.agent.aop.functionHook(args, 0, function (obj, args) {
41
- TraceContextManager.resume(cached_id);
42
- cached_id = null;
43
- });
44
- });
45
- });
46
-
47
33
  shimmer.wrap(mod, 'fetch', function(original) {
48
34
  return async function(...args) {
49
35
  var info = args[1] ? args[1] : {};
50
36
  var ctx = TraceContextManager._asyncLocalStorage.getStore();
51
37
 
52
38
  if (ctx) {
53
- interTxTraceAutoOn(ctx);
39
+ ctx.start_time = Date.now(); // start_time 설정 추가
40
+
41
+ TraceHelper.interTxTraceAutoOn(ctx);
54
42
 
55
43
  if (conf.getProperty('mtrace_enabled', false)) {
56
44
  addTraceHeaders(info, ctx);
57
45
  args[1] = info;
58
46
  }
47
+
48
+ if (args[0]) {
49
+ const url = new URL(args[0]);
50
+ ctx.httpc_url = url.pathname + url.search;
51
+ ctx.httpc_host = url.hostname;
52
+ ctx.httpc_port = url.port || (url.protocol === 'https:' ? 443 : 80);
53
+ ctx.active_httpc_hash = true;
54
+ }
59
55
  }
60
56
 
61
57
  try {
@@ -71,171 +67,100 @@ GlobalObserver.prototype.inject = function (mod, moduleName) {
71
67
  };
72
68
 
73
69
  function addTraceHeaders(info, ctx) {
74
- if (info.headers) {
75
- info.headers['x-wtap-po'] = transferPOID(ctx);
76
- } else {
77
- info.headers = {
78
- 'x-wtap-po': transferPOID(ctx)
79
- };
70
+ // 헤더 객체 초기화
71
+ if (!info.headers) {
72
+ info.headers = {};
80
73
  }
81
- if (conf.getProperty('stat_mtrace_enabled', false)) {
82
- info.headers[conf._trace_mtrace_spec_key1] = transferSPEC_URL(ctx);
74
+
75
+ info.headers['x-wtap-po'] = Transfer.POID();
76
+
77
+ if (conf.stat_mtrace_enabled) {
78
+ info.headers[conf._trace_mtrace_spec_key1] = Transfer.SPEC_URL(ctx);
83
79
  }
84
- if (ctx.mtid.isZero() === false) {
85
- info.headers[conf._trace_mtrace_caller_key] = transferMTID_CALLERTX(ctx);
80
+
81
+ if (!ctx.mtid.isZero()) {
82
+ info.headers[conf._trace_mtrace_caller_key] = Transfer.MTID_CALLERTX(ctx);
86
83
  }
84
+
85
+ ctx.mcallee = KeyGen.getMtid();
86
+ info.headers[conf._trace_mtrace_callee_key] = Hexa32.toString32(ctx.mcallee);
87
87
  }
88
88
 
89
89
  function handleResponse(ctx, args, response) {
90
90
  if (!ctx || !args[0]) return;
91
91
 
92
- const url = new URL(args[0]);
93
- setupContext(ctx, url);
94
-
95
- var step = createStep(ctx, url);
96
-
97
- if (!response.ok && transaction_status_error_enable) {
98
- recordError(ctx, step, response);
92
+ // Error handling for 4xx, 5xx responses
93
+ if (!response.ok && response.status >= 400 && transaction_status_error_enable) {
94
+ let error = {
95
+ class: response.statusText,
96
+ message: ''
97
+ }
98
+ interceptorError(response.status, error, ctx);
99
99
  }
100
100
 
101
- ctx.profile.push(step);
101
+ endHttpc(ctx);
102
102
  }
103
103
 
104
104
  function handleError(ctx, args, err) {
105
105
  if (!ctx || !args[0]) return;
106
- ctx.error_class = err.name || err.constructor?.name || 'HttpError';
107
- ctx.error_message = err.message;
108
-
109
- const url = new URL(args[0]);
110
- setupContext(ctx, url);
111
106
 
112
- var step = createStep(ctx, url);
107
+ const networkErrorToStatusCode = {
108
+ 'ECONNREFUSED': 503,
109
+ 'ETIMEDOUT': 504,
110
+ 'ENOTFOUND': 502,
111
+ 'ECONNRESET': 503,
112
+ 'EPIPE': 503,
113
+ 'EHOSTUNREACH': 503,
114
+ };
115
+ const statusCode = networkErrorToStatusCode[err.code] || 500;
113
116
 
114
117
  if (transaction_status_error_enable) {
115
- recordError(ctx, step, err);
118
+ let error = {
119
+ class: err.code || err.name,
120
+ message: err.message || ''
121
+ }
122
+ interceptorError(statusCode, error, ctx);
116
123
  }
117
124
 
118
- ctx.profile.push(step);
125
+ endHttpc(ctx);
119
126
  }
120
127
 
121
- function setupContext(ctx, url) {
122
- ctx.httpc_host = url.hostname;
123
- ctx.httpc_url = url.pathname;
124
- ctx.httpc_port = url.port || (url.protocol === 'https:' ? 443 : 80);
125
- }
128
+ function interceptorError(statusCode, error, ctx) {
129
+ if (!ctx) {
130
+ return;
131
+ }
126
132
 
127
- function createStep(ctx, url) {
128
- var step = new HttpStepX();
129
- step.start_time = ctx.getElapsedTime();
130
- step.url = HashUtil.hashFromString(ctx.httpc_url);
131
- DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url);
132
- step.host = HashUtil.hashFromString(ctx.httpc_host);
133
- DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host);
134
- step.port = ctx.httpc_port;
135
- return step;
136
- }
133
+ ctx.status = statusCode;
134
+ let errors = [];
135
+ let error_message = 'Request failed with status code ';
137
136
 
138
- function recordError(ctx, step, response) {
139
- if (step.error.isZero()) {
140
- const errorMessage = ctx.error_message = response.statusText || (response.cause ? response.cause.message : '') || response.message || 'Unknown error';
141
- step.error = StatError.addError(response.status || null, errorMessage, ctx.service_hash, TextTypes.HTTPC_URL, step.url);
142
-
143
- if (response.status) {
144
- if (response.status >= 400 && response.status < 500) {
145
- ctx.error_class = `HttpClientError`;
146
- } else if (response.status >= 500) {
147
- ctx.error_class = `HttpServerError`;
148
- } else {
149
- ctx.error_class = `HttpError`;
150
- }
137
+ if (statusCode >= 400 && !ctx.error) {
138
+ ctx.error = 1;
139
+
140
+ errors.push(error.class);
141
+ if (error.message) {
142
+ errors.push(error.message);
151
143
  } else {
152
- ctx.error_class = 'HttpError';
144
+ errors.push(error_message + statusCode);
153
145
  }
154
146
 
155
- if (ctx.error.isZero()) {
156
- ctx.error = step.error;
157
- ctx.statusCode = response.status || null;
158
- ctx.statusMessage = errorMessage;
159
- }
147
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
160
148
  }
161
149
  }
162
150
 
163
- var transfer_poid;
164
- function transferPOID(ctx) {
165
- if (transfer_poid)
166
- return transfer_poid;
167
- transfer_poid = Hexa32.toString32(SecurityMaster.PCODE) + ','
168
- + Hexa32.toString32(SecurityMaster.OKIND) + ',' + Hexa32.toString32(SecurityMaster.OID);
169
- return transfer_poid;
170
- }
171
-
172
- function transferMTID_CALLERTX(ctx) {
173
- if (ctx.transfer_id)
174
- return ctx.transfer_id;
175
- var x = Hexa32.toString32(ctx.mtid) + ',' + (ctx.mdepth + 1) + ',' + Hexa32.toString32(ctx.txid);
176
- ctx.transfer_id = x;
177
- return ctx.transfer_id;
178
- }
179
-
180
- function transferSPEC_URL(ctx) {
181
- if (ctx.transfer_info)
182
- return ctx.transfer_info;
183
- var x = conf.mtrace_spec + ',' + ctx.service_hash;
184
- ctx.transfer_info = x;
185
- return ctx.transfer_info;
186
- }
187
-
188
- var check_seq = 1;
189
- function interTxTraceAutoOn(ctx) {
190
- if (conf.mtrace_enabled == false || ctx.httpc_checked || ctx.mtid.isZero() === false)
151
+ function endHttpc(ctx) {
152
+ if (ctx == null) {
191
153
  return;
192
- ctx.httpc_checked = true;
193
- if (conf.mtrace_rate >= 100) {
194
- ctx.mtid = KeyGen.next();
195
- return;
196
- }
197
- check_seq++;
198
- switch (Math.floor(conf.mtrace_rate / 10)) {
199
- case 10:
200
- ctx.mtid = KeyGen.next();
201
- break;
202
- case 9:
203
- if (check_seq % 10 !== 0)
204
- ctx.mtid = KeyGen.next();
205
- break;
206
- case 8:
207
- if (check_seq % 5 !== 0)
208
- ctx.mtid = KeyGen.next();
209
- break;
210
- case 7:
211
- if (check_seq % 4 !== 0)
212
- ctx.mtid = KeyGen.next();
213
- break;
214
- case 6:
215
- if (check_seq % 3 !== 0)
216
- ctx.mtid = KeyGen.next();
217
- break;
218
- case 5:
219
- if (check_seq % 2 === 0)
220
- ctx.mtid = KeyGen.next();
221
- break;
222
- case 4:
223
- if (check_seq % 3 === 0 || check_seq % 5 === 0)
224
- ctx.mtid = KeyGen.next();
225
- break;
226
- case 3:
227
- if (check_seq % 4 === 0 || check_seq % 5 === 0)
228
- ctx.mtid = KeyGen.next();
229
- break;
230
- case 2:
231
- if (check_seq % 5 === 0)
232
- ctx.mtid = KeyGen.next();
233
- break;
234
- case 1:
235
- if (check_seq % 10 === 0)
236
- ctx.mtid = KeyGen.next();
237
- break;
238
154
  }
155
+
156
+ ctx.active_httpc_hash = false;
157
+ let urls = `${ctx.httpc_host}:${ctx.httpc_port}${ctx.httpc_url}`;
158
+ let httpcDatas = [urls, ctx.mcallee];
159
+ ctx.elapsed = Date.now() - ctx.start_time;
160
+ TraceHttpc.isSlowHttpc(ctx);
161
+ AsyncSender.send_packet(PacketTypeEnum.TX_HTTPC, ctx, httpcDatas);
239
162
  }
240
163
 
164
+ // interTxTraceAutoOn function moved to util/trace-helper.js
165
+
241
166
  exports.GlobalObserver = GlobalObserver;