whatap 1.0.6 → 1.0.7

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(chmod:*)",
5
+ "Bash(./fix_whatap_context.sh)"
6
+ ],
7
+ "deny": [],
8
+ "ask": []
9
+ }
10
+ }
package/lib/core/agent.js CHANGED
@@ -9,7 +9,9 @@ var os = require('os'),
9
9
  path = require('path'),
10
10
  child_process = require('child_process'),
11
11
  properLock = require('proper-lockfile'),
12
- crypto = require('crypto');
12
+ crypto = require('crypto'),
13
+ cluster = require('cluster');
14
+
13
15
 
14
16
  const RequestLog = require('../requestlog');
15
17
 
@@ -364,6 +366,9 @@ NodeAgent.prototype.openPortFile = function(filepath) {
364
366
  * @returns {number|null} - Allocated port number or null if failed
365
367
  */
366
368
  NodeAgent.prototype.getPortNumber = function(port, home) {
369
+ // Node.js cluster 모드 감지 (isPM2ClusterMode 호출 전에 실행)
370
+ this.isClusterMode();
371
+
367
372
  port = port || 6600;
368
373
  home = home || process.env.WHATAP_HOME;
369
374
 
@@ -615,6 +620,29 @@ NodeAgent.prototype.updateConfig = function(home, optKey, optValue) {
615
620
  }
616
621
  };
617
622
 
623
+ /**
624
+ * Detect Node.js cluster mode and set environment variables
625
+ * This allows Node.js cluster to work the same way as PM2 cluster mode
626
+ */
627
+ NodeAgent.prototype.isClusterMode = function() {
628
+ // PM2 환경 변수가 이미 있으면 skip
629
+ if (process.env.pm_id !== undefined) {
630
+ return;
631
+ }
632
+
633
+ // Node.js cluster worker인 경우 PM2 cluster 형태로 환경 변수 설정
634
+ if (cluster.worker) {
635
+ process.env.pm_id = cluster.worker.id.toString();
636
+
637
+ // instances 값은 실제로는 알 수 없지만, 2 이상으로 설정하여 클러스터 모드 활성화
638
+ if (!process.env.instances) {
639
+ process.env.instances = '2';
640
+ }
641
+
642
+ Logger.print("WHATAP-120", `Node.js cluster mode detected: worker ${cluster.worker.id}`, false);
643
+ }
644
+ };
645
+
618
646
  /**
619
647
  * Check if running in PM2 cluster mode
620
648
  * @returns {boolean} - True if PM2 cluster mode
@@ -139,6 +139,7 @@ HttpObserver.prototype.__createTransactionObserver = function (callback, isHttps
139
139
  String(ctx.isStaticContents),
140
140
  req.method
141
141
  ];
142
+ console.log(`ctx.userid: ${ctx.userid}`)
142
143
 
143
144
  aop.after(res, 'end', function (obj, args) {
144
145
  if (ctx == null) {
@@ -219,16 +220,12 @@ function initCtx(req, res) {
219
220
  remote_addr = remote_addr.split(',')[0].trim();
220
221
  }
221
222
  ctx.remoteIp = IPUtil.checkIp4(remote_addr);
222
- switch (conf.trace_user_using_type || 3) {
223
- case 1:
224
- ctx.userid = Long.fromNumber(ctx.remoteIp);
225
- break;
226
- case 2:
227
- // MeterUsers.add(ctx.userid);
228
- break;
229
- case 3:
223
+ if(conf.getProperty('trace_user_enabled', true)){
224
+ if(conf.getProperty('trace_user_using_ip', true)){
225
+ ctx.userid = ctx.remoteIp;
226
+ }else{
230
227
  ctx.userid = UserIdUtil.getUserId(req, res, 0);
231
- break;
228
+ }
232
229
  }
233
230
  } catch (e) {
234
231
  }
@@ -521,6 +521,8 @@ SocketIOObserver.prototype.__initCtx = function(socket, args, emitType, contextI
521
521
  const ctx = TraceContextManager.start();
522
522
  if (!ctx) return null;
523
523
 
524
+ ctx.service_name = "/socket.io";
525
+
524
526
  var remote_addr;
525
527
  var remoteAddress = contextInfo.remoteAddress || (socket && socket.conn && socket.conn.remoteAddress);
526
528
 
@@ -530,12 +532,11 @@ SocketIOObserver.prototype.__initCtx = function(socket, args, emitType, contextI
530
532
  }
531
533
  }
532
534
 
533
- ctx.service_name = "/socket.io";
534
-
535
- if (remote_addr) {
536
- remote_addr = IPUtil.checkIp4(remote_addr);
537
- ctx.remoteIp = IPUtil.stringToInt(remote_addr);
538
- ctx.userid = ctx.remoteIp;
535
+ if(remote_addr){
536
+ ctx.remoteIp = IPUtil.checkIp4(remote_addr);
537
+ if(conf.getProperty('trace_user_enabled', true)){
538
+ ctx.userid = ctx.remoteIp;
539
+ }
539
540
  }
540
541
 
541
542
  // 기본값 설정
@@ -9,10 +9,7 @@ var TraceContextManager = require('../trace/trace-context-manager'),
9
9
  IPUtil = require('../util/iputil'),
10
10
  Logger = require('../logger');
11
11
  const {Detector: URLPatternDetector} = require("../trace/serviceurl-pattern-detector");
12
- const DateUtil = require('../util/dateutil');
13
- const SecurityMaster = require('../net/security-master');
14
12
  const shimmer = require('../core/shimmer');
15
- const HashUtil = require('../util/hashutil');
16
13
  const AsyncSender = require('../udp/async_sender');
17
14
  const PacketTypeEnum = require('../udp/packet_type_enum');
18
15
  const os = require('os');
@@ -390,6 +387,8 @@ WebsocketObserver.prototype.__initCtx = function(connection, data, emitType, con
390
387
  const ctx = TraceContextManager.start();
391
388
  if (!ctx) return null;
392
389
 
390
+ ctx.service_name = "/websocket";
391
+
393
392
  var remote_addr;
394
393
  var remoteAddress = contextInfo.remoteAddress;
395
394
 
@@ -399,12 +398,11 @@ WebsocketObserver.prototype.__initCtx = function(connection, data, emitType, con
399
398
  }
400
399
  }
401
400
 
402
- ctx.service_name = "/websocket";
403
-
404
- if (remote_addr) {
405
- remote_addr = IPUtil.checkIp4(remote_addr);
406
- ctx.remoteIp = IPUtil.stringToInt(remote_addr);
407
- ctx.userid = ctx.remoteIp;
401
+ if(remote_addr){
402
+ ctx.remoteIp = IPUtil.checkIp4(remote_addr);
403
+ if(conf.getProperty('trace_user_enabled', true)){
404
+ ctx.userid = ctx.remoteIp;
405
+ }
408
406
  }
409
407
 
410
408
  // 기본값 설정
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "1.0.6",
5
- "releaseDate": "20251030",
4
+ "version": "1.0.7",
5
+ "releaseDate": "20251106",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},