From 2cefecaf238de40d78a7c22a7bf85c8d913a5dd4 Mon Sep 17 00:00:00 2001 From: Mariano De Maio Date: Tue, 22 Aug 2023 17:55:20 -0300 Subject: [PATCH] Gt 1361 correlation id preserving (#373) * CQL issue with connection pool exhaustion * GT-1361 preserving correlationId into the calls done to other HTTP compnoents --- .../a2d2/corewih/ServiceRestAPIDelegate.java | 5 ++++- fhir-helpers/pom.xml | 2 +- fhir-query-helper-base/pom.xml | 2 +- .../fhir/helper/CorrelationIdInterceptor.java | 16 ++++++++++++++++ .../fhir/helper/QueryingServerHelperBase.java | 4 +++- fhir-query-helper-dstu2/pom.xml | 2 +- fhir-query-helper-dstu3/pom.xml | 2 +- fhir-query-helper-r4/pom.xml | 2 +- oauth-helpers/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/CorrelationIdInterceptor.java diff --git a/core-wih/src/main/java/io/elimu/a2d2/corewih/ServiceRestAPIDelegate.java b/core-wih/src/main/java/io/elimu/a2d2/corewih/ServiceRestAPIDelegate.java index 37e1879c..8e4ea987 100644 --- a/core-wih/src/main/java/io/elimu/a2d2/corewih/ServiceRestAPIDelegate.java +++ b/core-wih/src/main/java/io/elimu/a2d2/corewih/ServiceRestAPIDelegate.java @@ -29,6 +29,7 @@ import org.kie.api.runtime.process.WorkItemManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -131,7 +132,9 @@ else if (token != null){ else { logger.warn("No authentication for the rest api request " + url); } - + if (!headers.containsKey("X-Correlation-ID")) { + headers.add("X-Correlation-ID", MDC.get("correlationId")); + } HttpEntity entity = new HttpEntity<>(body, headers); logger.debug("Prepared http entity"); diff --git a/fhir-helpers/pom.xml b/fhir-helpers/pom.xml index c1c6900d..2eb34ff5 100644 --- a/fhir-helpers/pom.xml +++ b/fhir-helpers/pom.xml @@ -20,7 +20,7 @@ 4.0.0 io.elimu.a2d2 fhir-helpers - 0.0.14 + 0.0.15 jar fhir-helpers http://maven.apache.org diff --git a/fhir-query-helper-base/pom.xml b/fhir-query-helper-base/pom.xml index 67d03643..53f5f2b6 100644 --- a/fhir-query-helper-base/pom.xml +++ b/fhir-query-helper-base/pom.xml @@ -27,7 +27,7 @@ fhir-query-helper-base - 0.0.14 + 0.0.15 CDS Helper base diff --git a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/CorrelationIdInterceptor.java b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/CorrelationIdInterceptor.java new file mode 100644 index 00000000..81786cd8 --- /dev/null +++ b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/CorrelationIdInterceptor.java @@ -0,0 +1,16 @@ +package io.elimu.a2d2.cds.fhir.helper; + +import org.slf4j.MDC; + +import ca.uhn.fhir.rest.client.interceptor.SimpleRequestHeaderInterceptor; + +public class CorrelationIdInterceptor extends SimpleRequestHeaderInterceptor { + + private static final String CORRELATION_ID_HEADER_NAME = "X-Correlation-ID"; + private static final String CORRELATION_ID_LOG_VAR_NAME = "correlationId"; + + public CorrelationIdInterceptor() { + super(CORRELATION_ID_HEADER_NAME, MDC.get(CORRELATION_ID_LOG_VAR_NAME)); + } + +} diff --git a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java index fb2a45ff..5e7aa315 100644 --- a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java +++ b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java @@ -301,8 +301,10 @@ protected FhirResponse runWithInterceptors(QueryingCallback callback, client.registerInterceptor(i); } SingleAuthInterceptor singleAuth = new SingleAuthInterceptor(); + CorrelationIdInterceptor correlationId = new CorrelationIdInterceptor(); client.registerInterceptor(singleAuth); client.registerInterceptor(tracker); + client.registerInterceptor(correlationId); try { result = callback.execute(client); } catch (RuntimeException t) { @@ -312,8 +314,8 @@ protected FhirResponse runWithInterceptors(QueryingCallback callback, log.debug("Unregistering interceptor " + i); client.unregisterInterceptor(i); } + client.unregisterInterceptor(correlationId); client.unregisterInterceptor(singleAuth); - client.unregisterInterceptor(tracker); }; } finally { diff --git a/fhir-query-helper-dstu2/pom.xml b/fhir-query-helper-dstu2/pom.xml index da79cd15..876f1d09 100644 --- a/fhir-query-helper-dstu2/pom.xml +++ b/fhir-query-helper-dstu2/pom.xml @@ -25,7 +25,7 @@ fhir-query-helper-dstu2 - 0.0.14 + 0.0.15 jar CDS Helper diff --git a/fhir-query-helper-dstu3/pom.xml b/fhir-query-helper-dstu3/pom.xml index a741a774..85dce595 100644 --- a/fhir-query-helper-dstu3/pom.xml +++ b/fhir-query-helper-dstu3/pom.xml @@ -26,7 +26,7 @@ fhir-query-helper-dstu3 - 0.0.14 + 0.0.15 jar CDS Helper DSTU3 diff --git a/fhir-query-helper-r4/pom.xml b/fhir-query-helper-r4/pom.xml index d01938d8..397fdc41 100644 --- a/fhir-query-helper-r4/pom.xml +++ b/fhir-query-helper-r4/pom.xml @@ -26,7 +26,7 @@ fhir-query-helper-r4 - 0.0.14 + 0.0.15 jar CDS Helper R4 diff --git a/oauth-helpers/pom.xml b/oauth-helpers/pom.xml index f9a623ab..82b7ba6e 100644 --- a/oauth-helpers/pom.xml +++ b/oauth-helpers/pom.xml @@ -27,7 +27,7 @@ oauth-helpers - 0.0.14 + 0.0.15 OAuth Helper diff --git a/pom.xml b/pom.xml index ed5e62af..90e1a050 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 3.21.8 2.23.0 4.0.1 - 0.0.14 + 0.0.15 2.3.30 0.8.7 2.3.1