Commit 8683e419 authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'users/Vibhuti/filterOrdering' into 'master'

Adding order in MDC filter

See merge request !31
parents a98db565 68ab3b60
Pipeline #10648 failed with stages
in 2 minutes and 35 seconds
......@@ -21,7 +21,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.0.28</version>
<version>0.0.29</version>
<name>core-lib-azure</name>
<properties>
......
......@@ -4,6 +4,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.Filter;
......@@ -17,9 +18,17 @@ import java.util.Map;
/**
* MDC Filter for logging.
* Condition 1: MDC filter should be called before any filter which contains logging logic, like TransactionLogFilter
* Condition 2: MDC filter should be called after OrderedRequestContextFilter, so that the request scope is set
* Filter with lowest order value is picked up first
* The order of TransactionLogFilter is not set, hence it picks up default value which is Ordered.LOWEST_PRECEDENCE (2147483647)
* The order of OrderedRequestContextFilter is -105
* Hence setting the order of MDC filter as -104
* So now order of calling the filters becomes: OrderedRequestContextFilter --> MDC filter --> ... --> TransactionLogFilter
*/
@Component
@ConditionalOnProperty(value = "logging.mdccontext.enabled", havingValue = "true", matchIfMissing = false)
@Order(-104)
public class Slf4jMDCFilter implements Filter {
@Autowired
private DpsHeaders dpsHeaders;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment