From 47062bff18bff46a840274efef1c0ae3091ca40e Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 21 Apr 2023 16:12:12 +0200 Subject: feat(log): add MDC based ID to correlate single HTTP requests --- .../eaaf/core/impl/utils/TransactionIdUtils.java | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'eaaf_core_utils/src/main') diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/TransactionIdUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/TransactionIdUtils.java index 212460d7..03a49221 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/TransactionIdUtils.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/TransactionIdUtils.java @@ -35,6 +35,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class TransactionIdUtils { + /** + * To correlate technical logs over one single request. + */ + public static final String MDC_REQUEST_ID = "amTxidHttpRequest"; + /** * To correlate technical logs over one single transactions. */ @@ -79,8 +84,9 @@ public class TransactionIdUtils { * */ public static void removeAllLoggingVariables() { - removeSessionId(); + removeRequestId(); removeTransactionId(); + removeSessionId(); removeServiceProviderId(); removeRemoteHost(); @@ -104,6 +110,42 @@ public class TransactionIdUtils { } + /** + * Get Id to correlate technical logs over one single request. + * + * @return Unique transaction Id + */ + public static String getRequestId() { + return org.slf4j.MDC.get(MDC_REQUEST_ID); + + } + + /** + * Set new random requestId as an UUID. + */ + public static void setRequestId() { + org.slf4j.MDC.put(MDC_REQUEST_ID, UUID.randomUUID().toString()); + + } + + /** + * Set Id to correlate technical logs over one single request. + * + * @param transactionId Unique transaction Id + */ + public static void setRequestId(final String transactionId) { + org.slf4j.MDC.put(MDC_REQUEST_ID, transactionId); + + } + + /** + * Remove requestId for Logging. + */ + public static void removeRequestId() { + org.slf4j.MDC.remove(MDC_REQUEST_ID); + + } + /** * Get Id to correlate technical logs over one single transactions. * @@ -185,5 +227,4 @@ public class TransactionIdUtils { } - } -- cgit v1.2.3