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.
@@ -264,6 +264,8 @@ var ConfigDefault = {
264
264
  "grpc_profile_stream_client_enabled": bool("grpc_profile_stream_client_enabled", true),
265
265
  "grpc_profile_stream_server_enabled": bool("grpc_profile_stream_server_enabled", true),
266
266
  "grpc_profile_ignore_method": bool("grpc_profile_ignore_method", true),
267
+
268
+ "oname_port_postfix_enabled": bool("oname_port_postfix_enabled", false),
267
269
  };
268
270
 
269
271
  ConfigDefault._hook_method_ignore_prefix = ConfigDefault.hook_method_ignore_prefixes.split(',');
@@ -105,7 +105,7 @@ var SecurityMaster = {
105
105
  }
106
106
 
107
107
  //OidUtil.setCmd(Configuration.getProperty("sun.java.command"));
108
- this.ONAME = OidUtil.mkOname(Configuration.getProperty("whatap.name", name_pattern));
108
+ this.ONAME = OidUtil.mkOname(Configuration.getProperty("whatap.name", name_pattern), port);
109
109
  this.OID = OidUtil.mkOid(this.ONAME);
110
110
 
111
111
  if (lastOid != this.OID) {
@@ -15,12 +15,20 @@ const KeyGen = require("../util/keygen");
15
15
  const HashUtil = require("../util/hashutil");
16
16
  const DataTextAgent = require("../data/datatext-agent");
17
17
  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;
18
21
 
19
22
  var GlobalObserver = function (agent) {
20
23
  this.agent = agent;
21
24
  this.packages = ['global'];
22
25
  }
23
26
 
27
+ var transaction_status_error_enable = conf.getProperty('transaction_status_error_enable', true);
28
+ conf.on('transaction_status_error_enable', function (newProps) {
29
+ transaction_status_error_enable = newProps;
30
+ })
31
+
24
32
  GlobalObserver.prototype.inject = function (mod, moduleName) {
25
33
  var self = this;
26
34
 
@@ -37,7 +45,7 @@ GlobalObserver.prototype.inject = function (mod, moduleName) {
37
45
  });
38
46
 
39
47
  shimmer.wrap(mod, 'fetch', function(original) {
40
- return function(...args) {
48
+ return async function(...args) {
41
49
  var info = args[1] ? args[1] : {};
42
50
  var ctx = TraceContextManager._asyncLocalStorage.getStore();
43
51
 
@@ -45,51 +53,103 @@ GlobalObserver.prototype.inject = function (mod, moduleName) {
45
53
  interTxTraceAutoOn(ctx);
46
54
 
47
55
  if (conf.mtrace_enabled) {
48
- if (info.headers) {
49
- info.headers['x-wtap-po'] = transferPOID(ctx);
50
- } else {
51
- info.headers = {
52
- 'x-wtap-po': transferPOID(ctx)
53
- };
54
- }
55
- if (conf.stat_mtrace_enabled) {
56
- info.headers[conf._trace_mtrace_spec_key1] = transferSPEC_URL(ctx);
57
- }
58
- if (conf.mtid_mtrace_enabled && ctx.mtid.isZero() === false) {
59
- info.headers[conf._trace_mtrace_caller_key] = transferMTID_CALLERTX(ctx);
60
- }
56
+ addTraceHeaders(info, ctx);
61
57
  args[1] = info;
62
58
  }
63
59
  }
64
60
 
65
- const promise = original.apply(this, args);
66
-
67
- promise.then(response => {
68
- var ctx = TraceContextManager._asyncLocalStorage.getStore();
69
- if (ctx && args[0]) {
70
- const url = new URL(args[0]);
71
- ctx.httpc_host = url.hostname;
72
- ctx.httpc_url = url.pathname;
73
- ctx.httpc_port = url.port || (url.protocol === 'https:' ? 443 : 80);
74
-
75
- var step = new HttpStepX();
76
- step.start_time = ctx.getElapsedTime();
77
- step.url = HashUtil.hashFromString(ctx.httpc_url);
78
- DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url);
79
- step.host = HashUtil.hashFromString(ctx.httpc_host);
80
- DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host);
81
- step.port = ctx.httpc_port;
82
-
83
- ctx.profile.push(step);
84
- }
85
- }).catch(e => {
86
- Logger.printError("WHATAP-704", "Promise error occurred during fetch: " + e, false);
87
- });
88
- return promise;
61
+ try {
62
+ const response = await original.apply(this, args);
63
+ handleResponse(ctx, args, response);
64
+ return response;
65
+ } catch (e) {
66
+ handleError(ctx, args, e);
67
+ throw e;
68
+ }
89
69
  };
90
70
  });
91
71
  };
92
72
 
73
+ 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
+ };
80
+ }
81
+ if (conf.stat_mtrace_enabled) {
82
+ info.headers[conf._trace_mtrace_spec_key1] = transferSPEC_URL(ctx);
83
+ }
84
+ if (conf.mtid_mtrace_enabled && ctx.mtid.isZero() === false) {
85
+ info.headers[conf._trace_mtrace_caller_key] = transferMTID_CALLERTX(ctx);
86
+ }
87
+ }
88
+
89
+ function handleResponse(ctx, args, response) {
90
+ if (!ctx || !args[0]) return;
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);
99
+ }
100
+
101
+ ctx.profile.push(step);
102
+ }
103
+
104
+ function handleError(ctx, args, error) {
105
+ if (!ctx || !args[0]) return;
106
+
107
+ const url = new URL(args[0]);
108
+ setupContext(ctx, url);
109
+
110
+ var step = createStep(ctx, url);
111
+
112
+ if (transaction_status_error_enable) {
113
+ recordError(ctx, step, error);
114
+ }
115
+
116
+ ctx.profile.push(step);
117
+ }
118
+
119
+ function setupContext(ctx, url) {
120
+ ctx.httpc_host = url.hostname;
121
+ ctx.httpc_url = url.pathname;
122
+ ctx.httpc_port = url.port || (url.protocol === 'https:' ? 443 : 80);
123
+ }
124
+
125
+ function createStep(ctx, url) {
126
+ var step = new HttpStepX();
127
+ step.start_time = ctx.getElapsedTime();
128
+ step.url = HashUtil.hashFromString(ctx.httpc_url);
129
+ DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url);
130
+ step.host = HashUtil.hashFromString(ctx.httpc_host);
131
+ DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host);
132
+ step.port = ctx.httpc_port;
133
+ return step;
134
+ }
135
+
136
+ function recordError(ctx, step, response) {
137
+ if (step.error.isZero()) {
138
+ var cleanUrl = ctx.httpc_url.split('?')[0];
139
+ ctx.service_name = URLPatternDetector.normalize(cleanUrl);
140
+ ctx.service_hash = HashUtil.hashFromString(ctx.service_name);
141
+
142
+ const errorMessage = response.statusText || (response.cause ? response.cause.message : '') || response.message || 'Unknown error';
143
+ step.error = StatError.addError(response.status || null, errorMessage, ctx.service_hash, TextTypes.HTTPC_URL, step.url);
144
+
145
+ if (ctx.error.isZero()) {
146
+ ctx.error = step.error;
147
+ ctx.statusCode = response.status || null;
148
+ ctx.statusMessage = errorMessage;
149
+ }
150
+ }
151
+ }
152
+
93
153
  var transfer_poid;
94
154
  function transferPOID(ctx) {
95
155
  if (transfer_poid)
@@ -51,13 +51,10 @@ const types = {
51
51
  bidi: 'bidi'
52
52
  };
53
53
 
54
- var _module;
55
-
56
54
  GRpcObserver.prototype.inject = function(mod, moduleName) {
57
55
  if (mod.__whatap_observe__) {
58
56
  return;
59
57
  }
60
- _module = mod;
61
58
  mod.__whatap_observe__ = true;
62
59
  Logger.initPrint("GRpcObserver");
63
60
 
@@ -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 && ctx.error.isZero()) {
203
- ctx.error = StatError.addError(obj.statusCode, obj.statusMessage,
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.statusMessage = obj.statusMessage;
206
+ ctx.statusTitle = obj.statusMessage;
207
+ ctx.statusMessage = ctx.error_message;
207
208
  }
208
209
 
209
210
  var requestPath = '';
@@ -244,6 +245,9 @@ function initCtx(req, res) {
244
245
  if (ignore_build_file_enabled && ignore_build_file_path && ignore_build_file_path.split(',').some(path => req.url.startsWith(path))) {
245
246
  return null;
246
247
  }
248
+ if( conf.getProperty('profile_enabled', true) === false ) {
249
+ return null;
250
+ }
247
251
 
248
252
  var ctx = TraceContextManager.start();
249
253
  if(ctx == null) { return null; }
@@ -466,10 +470,11 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
466
470
 
467
471
  if(profile_error_step_enabled && ctx.statusMessage){
468
472
  var step = new MessageStep();
469
- step.hash = HashUtil.hashFromString("EXCEPTION");
473
+ var title = ctx.statusTitle ? ctx.statusTitle : "EXCEPTION";
474
+ step.hash = HashUtil.hashFromString(title);
470
475
  step.start_time = ctx.getElapsedTime();
471
476
  step.desc = ctx.statusMessage;
472
- DataTextAgent.MESSAGE.add(step.hash, "EXCEPTION");
477
+ DataTextAgent.MESSAGE.add(step.hash, title);
473
478
  ctx.profile.push(step);
474
479
  }
475
480
 
@@ -649,7 +654,7 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
649
654
  if(mod.__whatap_observe__) { return; }
650
655
  mod.__whatap_observe__ = true;
651
656
  Logger.initPrint("HttpObserver");
652
- if( conf.profile_enabled === false ) { return; }
657
+ if( conf.getProperty('profile_enabled', true) === false ) { return; }
653
658
 
654
659
  aop.after(mod, 'createServer', function (obj, args, ret) {
655
660
  aop.before(ret, 'listen', function (obj, args) {
@@ -664,7 +669,7 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
664
669
  moduleName === 'https', obj);
665
670
  });
666
671
 
667
- if( conf.httpc_enabled === false ) { return; }
672
+ if( conf.getProperty('httpc_enabled', true) === false ) { return; }
668
673
 
669
674
  aop.both(mod, 'request',
670
675
  function (obj, args, lctx) {