diff options
author | 2018-04-25 15:28:48 +0300 | |
---|---|---|
committer | 2018-05-01 07:29:07 +0000 | |
commit | 0258442c39183fdd7e4812054d095cafdcab420d (patch) | |
tree | bb1bcfa60682f228356684145e50fa6ee94567f2 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org | |
parent | 65204c69a3eee5e8eeeccf9b1ed9503cdce63db5 (diff) |
Expose tracing context via log context service
Tracing context must be available to application code
when the application makes outbound calls.
Change-Id: Ica8e1f9d8e0bd6d37688a01a64c1fbedc126801c
Issue-ID: SDC-1264
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org')
3 files changed, 39 insertions, 2 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/MDCDelegate.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/MDCDelegate.java index 8d719a2da8..026d3fa99b 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/MDCDelegate.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/MDCDelegate.java @@ -50,6 +50,27 @@ class MDCDelegate { } /** + * Reads all context fields from MDC. + */ + static Map<ContextField, String> get() { + return get(ContextField.values()); + } + + /** + * Reads selected fields from MDC. + */ + static Map<ContextField, String> get(ContextField... fields) { + + Map<ContextField, String> values = new EnumMap<>(ContextField.class); + + for (ContextField key : fields) { + values.put(key, MDC.get(key.asKey())); + } + + return values; + } + + /** * Entirely replaces the logging MDC context with the content of the argument. Logging keys that are not present in * the input map will be cleared from MDC. */ diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/RequestContextProvider.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/RequestContextProvider.java index d79771c1c5..40684cc132 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/RequestContextProvider.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/RequestContextProvider.java @@ -30,10 +30,21 @@ class RequestContextProvider implements ContextProvider { private final ContextData data; - RequestContextProvider(ContextData contextData) { + private RequestContextProvider(ContextData contextData) { this.data = contextData; } + static RequestContextProvider from(ContextData contextData) { + return new RequestContextProvider(contextData); + } + + static ContextData to(Map<ContextField, String> values) { + return ContextData.builder() + .requestId(values.get(ContextField.REQUEST_ID)) + .serviceName(values.get(ContextField.SERVICE_NAME)) + .partnerName(values.get(ContextField.PARTNER_NAME)).build(); + } + @Override public Map<ContextField, String> values() { diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggingServiceProvider.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggingServiceProvider.java index 1a5d6facc2..9d4d507ac5 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggingServiceProvider.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggingServiceProvider.java @@ -45,7 +45,12 @@ public class SLF4JLoggingServiceProvider implements LoggingServiceProvider { @Override public void put(ContextData contextData) { Objects.requireNonNull(contextData, "Context data cannot be null"); - MDCDelegate.put(new RequestContextProvider(contextData), new GlobalContextProvider()); + MDCDelegate.put(RequestContextProvider.from(contextData), new GlobalContextProvider()); + } + + @Override + public ContextData get() { + return RequestContextProvider.to(MDCDelegate.get()); } @Override |