Skip to content

Commit

Permalink
fix: included sessionId extraction for MDC
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Dec 19, 2024
1 parent 30b0e77 commit 72abd20
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

import it.gov.pagopa.wispconverter.repository.model.enumz.WorkflowStatus;
import it.gov.pagopa.wispconverter.service.ReService;
import it.gov.pagopa.wispconverter.util.Constants;
import it.gov.pagopa.wispconverter.util.client.AbstractAppClientLoggingInterceptor;
import it.gov.pagopa.wispconverter.util.client.ClientServiceEnum;
import it.gov.pagopa.wispconverter.util.client.RequestResponseLoggingProperties;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.http.HttpMethod;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class DecouplerCachingClientLoggingInterceptor extends AbstractAppClientLoggingInterceptor {

private final Pattern sessionIdPattern = Pattern.compile("\\\"sessionId\\\":\\\"([a-zA-Z0-9-]+)\\\"");

public DecouplerCachingClientLoggingInterceptor(RequestResponseLoggingProperties clientLoggingProperties, ReService reService, Boolean isTracingOfClientOnREEnabled) {
super(clientLoggingProperties, reService, ClientServiceEnum.DECOUPLER);

Expand All @@ -36,7 +43,19 @@ protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) {

@Override
protected void setInMDCAfterClientResponse(String payload) {
// nothing to do
try {
if (payload != null && !payload.isBlank()) {
Matcher matcher = sessionIdPattern.matcher(payload);
if (matcher.find()) {
String sessionId = matcher.group(1);
if (sessionId != null && !sessionId.isBlank()) {
MDC.put(Constants.MDC_SESSION_ID, sessionId);
}
}
}
} catch (Exception e) {
// catch this but do nothing, as nothing is required to do
}
}

@Override
Expand Down

0 comments on commit 72abd20

Please sign in to comment.