summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src
diff options
context:
space:
mode:
authornrpandya <neenendra.pandya@att.com>2020-10-11 21:24:18 -0500
committernrpandya <neenendra.pandya@att.com>2020-10-11 23:17:11 -0500
commit969d2d7c2caed78d297ccf8e0ebc9120831c18b0 (patch)
treed0cf1ff7f4c99c0bc30d28bab41b9a7729cc19e1 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src
parentf99f3b921b20c8794b8b37b3926f7221b164338b (diff)
Add InvocationID to p_mdc field in audit logs
Add InvocationID in SLF4JLoggerWrapper for audit entry and exit Issue-ID: SDC-3312 Change-Id: Id19dd3cfff75a23f14d0a1d22520a2e967e46289 Signed-off-by: nrpandya <neenendra.pandya@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java3
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java7
3 files changed, 11 insertions, 1 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java
index c4e780fa8f..c08952a84d 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/AuditField.java
@@ -32,7 +32,8 @@ enum AuditField implements MDCField {
STATUS_CODE(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE),
RESPONSE_CODE(ONAPLogConstants.MDCs.RESPONSE_CODE),
RESPONSE_DESCRIPTION(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION),
- CLIENT_IP_ADDRESS(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS);
+ CLIENT_IP_ADDRESS(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS),
+ INVOCATION_ID(ONAPLogConstants.MDCs.INVOCATION_ID);
private final String key;
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java
index f85a6bbe95..54026098c1 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapper.java
@@ -17,6 +17,7 @@
package org.openecomp.sdc.logging.slf4j;
import java.text.SimpleDateFormat;
+import java.util.UUID;
import org.openecomp.sdc.logging.api.AuditData;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.MetricsData;
@@ -157,6 +158,7 @@ class SLF4JLoggerWrapper implements Logger {
safePutOnMdc(AuditField.RESPONSE_CODE, audit.getResponseCode());
safePutOnMdc(AuditField.RESPONSE_DESCRIPTION, audit.getResponseDescription());
safePutOnMdc(AuditField.CLIENT_IP_ADDRESS, audit.getClientIpAddress());
+ unsafePutOnMdc(AuditField.INVOCATION_ID, UUID.randomUUID().toString());
if (audit.getStatusCode() != null) {
unsafePutOnMdc(AuditField.STATUS_CODE, audit.getStatusCode().name());
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
index 2b98fc898f..6785c15355 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
@@ -221,6 +221,13 @@ public class SLF4JLoggerWrapperTest {
}
@Test
+ public void auditInvocationIdAvailable() {
+ SpyLogger spy = createSpy();
+ new SLF4JLoggerWrapper(spy).auditExit(AuditData.builder().build());
+ assertNotNull(spy.mdc().get(AuditField.INVOCATION_ID.asKey()));
+ }
+
+ @Test
public void metricsTargetEntityAvailableWhenPassed() {
final String targetEntity = "MetricsTargetEntity";
SpyLogger spy = createSpy();