summaryrefslogtreecommitdiff
path: root/eaaf_core_utils
diff options
context:
space:
mode:
authorThomas <>2023-04-21 16:12:12 +0200
committerThomas <>2023-04-21 16:12:12 +0200
commit47062bff18bff46a840274efef1c0ae3091ca40e (patch)
tree52306a56f6473b0a7a29c3ac96f5f93fb8d308f2 /eaaf_core_utils
parent9b2fe361e8c2b213a27634242ad07f891c35561e (diff)
downloadEAAF-Components-47062bff18bff46a840274efef1c0ae3091ca40e.tar.gz
EAAF-Components-47062bff18bff46a840274efef1c0ae3091ca40e.tar.bz2
EAAF-Components-47062bff18bff46a840274efef1c0ae3091ca40e.zip
feat(log): add MDC based ID to correlate single HTTP requests
Diffstat (limited to 'eaaf_core_utils')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/TransactionIdUtils.java45
1 files changed, 43 insertions, 2 deletions
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
@@ -36,6 +36,11 @@ import lombok.extern.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.
*/
public static final String MDC_TRANSACTION_ID = "transactionId";
@@ -79,8 +84,9 @@ public class TransactionIdUtils {
*
*/
public static void removeAllLoggingVariables() {
- removeSessionId();
+ removeRequestId();
removeTransactionId();
+ removeSessionId();
removeServiceProviderId();
removeRemoteHost();
@@ -105,6 +111,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.
*
* @return Unique transaction Id
@@ -185,5 +227,4 @@ public class TransactionIdUtils {
}
-
}