Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lnk 2116 logging improvements #744

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.hl7.fhir.r4.model.MeasureReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -66,8 +68,12 @@ public void generate(QueryPhase queryPhase) throws ExecutionException, Interrupt
AtomicInteger progress = new AtomicInteger(0);
List<PatientOfInterestModel> pois = measureContext.getPatientsOfInterest(queryPhase);

var contextMapCopy = MDC.getCopyOfContextMap();

forkJoinPool.submit(() -> pois.parallelStream().forEach(patient -> {

MDC.setContextMap(contextMapCopy);
edward-miller-lcg marked this conversation as resolved.
Show resolved Hide resolved

forkJoinPool.submit(() -> pois.parallelStream().forEach(patient -> {
if (StringUtils.isEmpty(patient.getId())) {
logger.error("Patient {} has no ID; cannot generate measure report", patient);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hl7.fhir.r4.model.MeasureReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -402,6 +403,9 @@ private Report generateResponse(TenantService tenantService, LinkCredentials use
report.setVersion(existingReport.getVersion());
}

MDC.put("report", String.format("%s-%s-%s",
tenantService.getConfig().getId(), report.getId(), report.getVersion()));

tenantService.saveReport(report, reportContext.getPatientLists());

this.eventService.triggerEvent(tenantService, EventTypes.BeforePatientDataQuery, criteria, reportContext);
Expand Down Expand Up @@ -454,6 +458,7 @@ private Report generateResponse(TenantService tenantService, LinkCredentials use
}
} finally {
tenantLock.unlock();
MDC.clear();
}

this.stopwatchManager.storeMetrics(tenantService.getConfig().getId(), report.getId(), report.getVersion());
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<property name="LOG_FILE" value="logs/link-api.log"/>
<property name="LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE" value="100MB"/>
<property name="LOGBACK_ROLLINGPOLICY_MAX_HISTORY" value="0"/>
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(${LOGGED_APPLICATION_NAME:-}[%15.15t] [%X{report}]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- ${LOGGED_APPLICATION_NAME:-}[%t] [%X{report}] ${LOG_CORRELATION_PATTERN:-}%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>

<logger name="com.lantanagroup.link" level="DEBUG"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hl7.fhir.r4.model.Patient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -110,7 +111,10 @@ public void loadInitialPatientData(ReportCriteria criteria, ReportContext contex
AtomicInteger progress = new AtomicInteger(0);

try {
var contextMapCopy = MDC.getCopyOfContextMap();
patientFork.submit(() -> patientsOfInterest.parallelStream().map(poi -> {
MDC.setContextMap(contextMapCopy);

int poiIndex = patientsOfInterest.indexOf(poi);

//noinspection unused
Expand Down Expand Up @@ -177,10 +181,12 @@ public void loadInitialPatientData(ReportCriteria criteria, ReportContext contex
progress.set(0);

try {
var contextMapCopy = MDC.getCopyOfContextMap();
// loop through the patient ids to retrieve the patientData using each patient.
List<Patient> patients = new ArrayList<>(patientMap.values());

patientDataFork.submit(() -> patients.parallelStream().map(patient -> {
MDC.setContextMap(contextMapCopy);
logger.debug(String.format("Beginning to load data for patient with logical ID %s", patient.getIdElement().getIdPart()));

PatientData patientData = null;
Expand Down Expand Up @@ -210,7 +216,9 @@ public void loadSupplementalPatientData(ReportCriteria criteria, ReportContext c
AtomicInteger progress = new AtomicInteger(0);

try {
var contextMapCopy = MDC.getCopyOfContextMap();
patientDataFork.submit(() -> patientsOfInterest.parallelStream().map(poi -> {
MDC.setContextMap(contextMapCopy);
logger.debug(String.format("Continuing to load data for patient with logical ID %s", poi.getId()));

Bundle patientBundle = com.lantanagroup.link.db.model.PatientData.asBundle(this.tenantService.findPatientData(context.getMasterIdentifierValue(), poi.getId()));
Expand Down