@yolo-croket-dev/core 1.10.1 → 1.10.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.
@@ -67,6 +67,18 @@ export declare function registerRmqObservation(owner: object, observer: RmqConne
67
67
  * @process 관찰 대상이 아니면 undefined를 반환한다.
68
68
  */
69
69
  export declare function getRmqDiagnosticSnapshot(owner: object): Snapshot | undefined;
70
+ /**
71
+ * @author jun
72
+ * @description 현재 메시지의 핸들러 오류 상세를 LoggingServiceInterceptor가 기록할 수 있음을 표시한다.
73
+ * @process 메시지 객체만 약하게 참조하여 동시 요청과 재전달 메시지를 구분한다.
74
+ */
75
+ export declare function markRmqHandlerLogging(message: unknown): void;
76
+ /**
77
+ * @author jun
78
+ * @description 현재 메시지에 핸들러 오류 상세 로거가 있는지 확인한다.
79
+ * @process RPCInterceptor의 중복 상세 기록 여부를 결정한다.
80
+ */
81
+ export declare function hasRmqHandlerLogging(message: unknown): boolean;
70
82
  /**
71
83
  * @author jun
72
84
  * @description 이미 기록한 오류 상세를 표시한다.
@@ -26,13 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.createDiagnosticRmqClient = exports.getRecordedRmqDiagnosticError = exports.recordRmqDiagnosticError = exports.getRmqDiagnosticSnapshot = exports.registerRmqObservation = exports.withRmqConnectionName = exports.createRmqObserver = exports.RmqConnectionObserver = exports.isRmqDiagnosticsEnabled = void 0;
29
+ exports.createDiagnosticRmqClient = exports.getRecordedRmqDiagnosticError = exports.recordRmqDiagnosticError = exports.hasRmqHandlerLogging = exports.markRmqHandlerLogging = exports.getRmqDiagnosticSnapshot = exports.registerRmqObservation = exports.withRmqConnectionName = exports.createRmqObserver = exports.RmqConnectionObserver = exports.isRmqDiagnosticsEnabled = void 0;
30
30
  const node_crypto_1 = require("node:crypto");
31
31
  const node_os_1 = __importDefault(require("node:os"));
32
32
  const microservices_1 = require("@nestjs/microservices");
33
33
  const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
34
34
  const observations = new WeakMap();
35
35
  const recordedErrors = new WeakMap();
36
+ const handlerLoggingMessages = new WeakSet();
36
37
  let logger;
37
38
  /**
38
39
  * @author jun
@@ -245,6 +246,25 @@ function getRmqDiagnosticSnapshot(owner) {
245
246
  return (_a = observations.get(owner)) === null || _a === void 0 ? void 0 : _a.snapshot();
246
247
  }
247
248
  exports.getRmqDiagnosticSnapshot = getRmqDiagnosticSnapshot;
249
+ /**
250
+ * @author jun
251
+ * @description 현재 메시지의 핸들러 오류 상세를 LoggingServiceInterceptor가 기록할 수 있음을 표시한다.
252
+ * @process 메시지 객체만 약하게 참조하여 동시 요청과 재전달 메시지를 구분한다.
253
+ */
254
+ function markRmqHandlerLogging(message) {
255
+ if (message !== null && typeof message === 'object')
256
+ handlerLoggingMessages.add(message);
257
+ }
258
+ exports.markRmqHandlerLogging = markRmqHandlerLogging;
259
+ /**
260
+ * @author jun
261
+ * @description 현재 메시지에 핸들러 오류 상세 로거가 있는지 확인한다.
262
+ * @process RPCInterceptor의 중복 상세 기록 여부를 결정한다.
263
+ */
264
+ function hasRmqHandlerLogging(message) {
265
+ return message !== null && typeof message === 'object' && handlerLoggingMessages.has(message);
266
+ }
267
+ exports.hasRmqHandlerLogging = hasRmqHandlerLogging;
248
268
  // Contains error metadata only, never per-request context: one RMQ error can reject concurrent calls.
249
269
  /**
250
270
  * @author jun
@@ -161,6 +161,8 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
161
161
  loggingSpan.setTag('traceId', traceId);
162
162
  loggingSpan.setTag('messagePattern', pattern);
163
163
  }
164
+ if (connection)
165
+ (0, rmq_diagnostics_function_1.markRmqHandlerLogging)(originalMessage);
164
166
  return next.handle()
165
167
  .pipe((0, operators_1.tap)(() => {
166
168
  const elapsed = Date.now() - now;
@@ -207,7 +207,7 @@ let RPCInterceptor = class RPCInterceptor {
207
207
  msaLogger.debug('isRedeliveryMessage RETRY_COUNT_ZERO_OR_NO_RETRY true, 재처리하여 전달토록 하기', { traceId: ((_d = content.data.param) === null || _d === void 0 ? void 0 : _d.traceId) || 'RETRY_COUNT_ZERO_OR_NO_RETRY' });
208
208
  }
209
209
  const noAck = message.fields.routingKey.includes('ASYNC');
210
- let localErrorProcessor = async (err) => {
210
+ let localErrorProcessor = async (err, preHandlerError = false) => {
211
211
  var _a, _b;
212
212
  const errMsg = err.response ? err.response : err.message;
213
213
  const status = err.status ? err.status : 500;
@@ -280,7 +280,8 @@ let RPCInterceptor = class RPCInterceptor {
280
280
  }
281
281
  }
282
282
  const sendMessage = Buffer.from(JSON.stringify(abstractAmqpHandlerData));
283
- const diagnostic = startConnection
283
+ const delegatedDiagnostic = Boolean(startConnection && !preHandlerError && (0, rmq_diagnostics_function_1.hasRmqHandlerLogging)(message));
284
+ const diagnostic = startConnection && !delegatedDiagnostic
284
285
  ? (0, msa_logger_1.normalizeDiagnosticError)(err, isTimeoutError ? 'response_timeout' : 'service_error') : undefined;
285
286
  const diagnosticInfo = diagnostic ? {
286
287
  ...diagnostic.diagnosticInfo,
@@ -293,26 +294,35 @@ let RPCInterceptor = class RPCInterceptor {
293
294
  } : undefined;
294
295
  if (!isAck || diagnostic) {
295
296
  const currentContext = functions_1.AbortContext.getCurrentContext();
296
- msaLogger.warn(isAck ? 'RPCInterceptor 오류 처리' : '에러 응답 전송 처리', {
297
- traceId: execInterceptor.traceId,
298
- diagnosticInfo,
299
- }, diagnostic ? {
300
- error: diagnostic.details,
297
+ let logDetails = {
301
298
  reDeliveryCount,
302
299
  staticRetryCount,
303
300
  currentContext: (_a = currentContext === null || currentContext === void 0 ? void 0 : currentContext.requestId) !== null && _a !== void 0 ? _a : null,
304
- } : {
305
- error: {
306
- message: err.message,
307
- stack: err.stack,
308
- name: err.name,
309
- response: err.response,
310
- reDeliveryCount,
311
- staticRetryCount,
312
- },
313
- messagePattern: method,
314
- currentContext: currentContext && currentContext.requestId ? currentContext.requestId : null,
315
- });
301
+ };
302
+ if (diagnostic) {
303
+ logDetails = {
304
+ ...logDetails,
305
+ error: diagnostic.details,
306
+ };
307
+ }
308
+ else if (!delegatedDiagnostic) {
309
+ logDetails = {
310
+ error: {
311
+ message: err.message,
312
+ stack: err.stack,
313
+ name: err.name,
314
+ response: err.response,
315
+ reDeliveryCount,
316
+ staticRetryCount,
317
+ },
318
+ messagePattern: method,
319
+ currentContext: currentContext && currentContext.requestId ? currentContext.requestId : null,
320
+ };
321
+ }
322
+ msaLogger.warn(isAck ? 'RPCInterceptor 오류 처리' : '에러 응답 전송 처리', {
323
+ traceId: execInterceptor.traceId,
324
+ diagnosticInfo,
325
+ }, logDetails);
316
326
  }
317
327
  if (!isAck) {
318
328
  channel.sendToQueue(message.properties.replyTo, sendMessage, { correlationId: message.properties.correlationId });
@@ -344,7 +354,7 @@ let RPCInterceptor = class RPCInterceptor {
344
354
  }
345
355
  }
346
356
  catch (err) {
347
- await localErrorProcessor(err);
357
+ await localErrorProcessor(err, true);
348
358
  return new rxjs_1.Observable();
349
359
  }
350
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-croket-dev/core",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "author": "Yolo Co., Ltd.",
5
5
  "description": "Yolo commonization module",
6
6
  "main": "index.js",