From 244bbb121e91e1ccb883ec2fcb881cd40846a316 Mon Sep 17 00:00:00 2001 From: Rick Rongen Date: Fri, 5 Sep 2025 09:09:37 +0200 Subject: [PATCH] feat: initial commit --- .gitignore | 38 +++++ .idea/.gitignore | 8 + .idea/encodings.xml | 12 ++ .idea/misc.xml | 14 ++ .idea/vcs.xml | 7 + lib-1/pom.xml | 29 ++++ pom.xml | 33 ++++ spring-boot-common-utils/pom.xml | 88 ++++++++++ .../sb/util/logging/AccessLogFilter.java | 156 ++++++++++++++++++ .../sb/util/logging/EnableSfgSbLogging.java | 20 +++ .../util/logging/MdcLoggingConfiguration.java | 18 ++ .../sb/util/logging/MdcPropagator.java | 55 ++++++ .../MissingMdcLoggingConfiguration.java | 16 ++ .../util/logging/ServletAccessLogFilter.java | 39 +++++ .../logging/WebClientRequestIdForwarder.java | 28 ++++ .../util/logging/WebFluxAccessLogFilter.java | 38 +++++ .../main/resources/application-sfg-shared.yml | 23 +++ spring-boot-parent/pom.xml | 48 ++++++ 18 files changed, 670 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 lib-1/pom.xml create mode 100644 pom.xml create mode 100644 spring-boot-common-utils/pom.xml create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/AccessLogFilter.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/EnableSfgSbLogging.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcLoggingConfiguration.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcPropagator.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MissingMdcLoggingConfiguration.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/ServletAccessLogFilter.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebClientRequestIdForwarder.java create mode 100644 spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebFluxAccessLogFilter.java create mode 100644 spring-boot-common-utils/src/main/resources/application-sfg-shared.yml create mode 100644 spring-boot-parent/pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e90c560 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..463551f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..79073d8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/lib-1/pom.xml b/lib-1/pom.xml new file mode 100644 index 0000000..a9995ad --- /dev/null +++ b/lib-1/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + com.sligrofoodgroup.spring-boot-common + common + 1.0-SNAPSHOT + ../pom.xml + + + lib-1 + + + 17 + 17 + UTF-8 + + + + + org.springframework + spring-webflux + true + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..27c7d82 --- /dev/null +++ b/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + + scm:git:file://localhost/../sfg-sb-common-remote.git + file://../sfg-sb-common-remote.git + + + + com.sligrofoodgroup.spring-boot-common + spring-boot-parent + 1.0-SNAPSHOT + spring-boot-parent/pom.xml + + + common + pom + + spring-boot-parent + lib-1 + spring-boot-common-utils + + + + 17 + 17 + UTF-8 + + + diff --git a/spring-boot-common-utils/pom.xml b/spring-boot-common-utils/pom.xml new file mode 100644 index 0000000..67717f3 --- /dev/null +++ b/spring-boot-common-utils/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + + + com.sligrofoodgroup.spring-boot-common + common + 1.0-SNAPSHOT + ../pom.xml + + + spring-boot-common-utils + + + 17 + 17 + UTF-8 + + + + + org.projectlombok + lombok + compile + + + + org.slf4j + slf4j-api + provided + + + org.jetbrains + annotations + provided + + + + + io.projectreactor + reactor-core + true + + + jakarta.servlet + jakarta.servlet-api + provided + true + + + jakarta.annotation + jakarta.annotation-api + provided + + + + + io.micrometer + context-propagation + true + + + org.springframework + spring-webflux + true + + + org.springframework + spring-web + provided + + + org.springframework + spring-context + provided + + + org.springframework.boot + spring-boot-autoconfigure + provided + + + diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/AccessLogFilter.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/AccessLogFilter.java new file mode 100644 index 0000000..6e35a8c --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/AccessLogFilter.java @@ -0,0 +1,156 @@ +package com.sligrofoodgroup.sb.util.logging; + +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.MDC; +import org.slf4j.event.Level; +import org.springframework.http.HttpRequest; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.util.StopWatch; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +@Slf4j +class AccessLogFilter { + public static final String MDC_PREFIX = "req."; + public static final String MDC_METHOD = MDC_PREFIX + "method"; + public static final String MDC_URI = MDC_PREFIX + "uri"; + public static final String MDC_REQUEST_ID = MDC_PREFIX + "requestId"; + public static final String MDC_REAL_IP = MDC_PREFIX + "realIp"; + public static final String MDC_STATUS_CODE = MDC_PREFIX + "statusCode"; + public static final String MDC_DURATION_MS = MDC_PREFIX + "durationMs"; + public static final String MDC_BASE_SITE_ID = MDC_PREFIX + "baseSiteId"; + + public static final String HTTP_HEADER_X_FORWARDED_FOR = "X-Forwarded-For"; + public static final String HTTP_HEADER_X_REAL_IP = "X-Real-IP"; + public static final String HTTP_HEADER_X_REQUEST_ID = "X-Request-Id"; + public static final String HTTP_HEADER_BASE_SITE_ID = "X-Base-Site-Id"; + + @NotNull + Map getPropagationContext() { + return Map.of(MdcPropagator.MDC_TLA_NAME, MdcPropagator.getMdcContext()); + } + + private static InetAddress getRemoteAddress(@NotNull HttpRequest httpRequest) { + return getForwardedForAddress(httpRequest) + .or(() -> getRealIpAddress(httpRequest)) + .or(() -> getFromRemoteAddress(httpRequest)) + .orElse(null); + } + + private static @NotNull Optional getFromRemoteAddress(@NotNull HttpRequest httpRequest) { + try { + if (httpRequest instanceof final ServletServerHttpRequest servletServerHttpRequest) { + return Optional.ofNullable(servletServerHttpRequest.getRemoteAddress().getAddress()); + } + } catch (final NoClassDefFoundError ncdfe) { + // This will happen when we do not have WebMVC classes available + } + try { + if (httpRequest instanceof final ServerHttpRequest serverHttpRequest) { + return Optional.ofNullable(serverHttpRequest.getRemoteAddress()) + .map(InetSocketAddress::getAddress); + } + } catch (final NoClassDefFoundError ncdfe) { + // This may happen if we do not have WebFlux classes available + } + return Optional.empty(); + } + + private static @NotNull Optional getRealIpAddress(@NotNull HttpRequest httpRequest) { + return httpRequest.getHeaders() + .getOrEmpty(HTTP_HEADER_X_REAL_IP) + .stream() + .findFirst() + .map(host -> { + try { + return InetAddress.getByName(host); + } catch (UnknownHostException e) { + return null; + } + }); + } + + private static @NotNull Optional getForwardedForAddress(@NotNull HttpRequest httpRequest) { + return httpRequest.getHeaders() + .getOrEmpty(HTTP_HEADER_X_FORWARDED_FOR) + .stream() + .flatMap(line -> Arrays.stream(line.split(",")).map(String::trim)) + .findFirst() // todo filter untrusted + .map(host -> { + try { + return InetAddress.getByName(host); + } catch (UnknownHostException e) { + return null; + } + }); + } + + @NotNull + private String getBaseSiteId(@NotNull HttpRequest httpRequest) { + return Optional.ofNullable(httpRequest.getHeaders().getFirst(HTTP_HEADER_BASE_SITE_ID)).orElse("unknown"); + } + + void fillMdc(@NotNull final HttpRequest request) { + // todo, doesn't opentracing do this also? doesn't this conflict + String requestId = Optional.ofNullable(request.getHeaders().getFirst(HTTP_HEADER_X_REQUEST_ID)) + .orElseGet(() -> UUID.randomUUID().toString()); + MDC.put(MDC_METHOD, request.getMethod().name()); + MDC.put(MDC_URI, request.getURI().toString()); + MDC.put(MDC_REQUEST_ID, requestId); + MDC.put(MDC_REAL_IP, Optional.ofNullable(getRemoteAddress(request)).map(InetAddress::getHostAddress).orElse("unknown")); + MDC.put(MDC_BASE_SITE_ID, getBaseSiteId(request)); + } + + public AccessLogContex requestStart(@NotNull final HttpRequest request) { + final AccessLogContex accessLogContex = new AccessLogContex(request); + fillMdc(request); + return accessLogContex; + } + + public void clearMdc() { + MDC.remove(MDC_METHOD); + MDC.remove(MDC_URI); + MDC.remove(MDC_REQUEST_ID); + MDC.remove(MDC_REAL_IP); + } + + public static class AccessLogContex { + @NotNull + private final HttpRequest request; + @NotNull + public final StopWatch stopWatch; + + private AccessLogContex(@NotNull final HttpRequest request) { + this.request = request; + stopWatch = new StopWatch(); + stopWatch.start(); + } + + void requestEnd(@Nullable final HttpStatusCode statusCode, @NotNull final Throwable throwable) { + stopWatch.stop(); + log.makeLoggingEventBuilder(Level.WARN) + .addKeyValue(MDC_STATUS_CODE, Optional.ofNullable(statusCode).map(HttpStatusCode::value).map(Object::toString).orElse("n/a")) + .addKeyValue(MDC_DURATION_MS, stopWatch.getTotalTimeMillis()) + .setCause(throwable) + .log("Request {} {} {}", request.getMethod(), request.getURI(), statusCode); + } + + void requestEnd(@Nullable final HttpStatusCode statusCode) { + stopWatch.stop(); + log.makeLoggingEventBuilder(Level.WARN) + .addKeyValue(MDC_STATUS_CODE, Optional.ofNullable(statusCode).map(HttpStatusCode::value).map(Object::toString).orElse("n/a")) + .addKeyValue(MDC_DURATION_MS, stopWatch.getTotalTimeMillis()) + .log("Request {} {} {}", request.getMethod(), request.getURI(), statusCode); + } + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/EnableSfgSbLogging.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/EnableSfgSbLogging.java new file mode 100644 index 0000000..8f6611d --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/EnableSfgSbLogging.java @@ -0,0 +1,20 @@ +package com.sligrofoodgroup.sb.util.logging; + +import org.springframework.context.annotation.Import; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Import({ + ServletAccessLogFilter.class, + WebFluxAccessLogFilter.class, + MdcLoggingConfiguration.class, + MissingMdcLoggingConfiguration.class, + WebClientRequestIdForwarder.class, +}) +public @interface EnableSfgSbLogging { +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcLoggingConfiguration.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcLoggingConfiguration.java new file mode 100644 index 0000000..c239fde --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcLoggingConfiguration.java @@ -0,0 +1,18 @@ +package com.sligrofoodgroup.sb.util.logging; + +import io.micrometer.context.ContextRegistry; +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConditionalOnClass(ContextRegistry.class) +class MdcLoggingConfiguration { + @PostConstruct + public void registerMdcPropagation() { + log.info("Enabling MDC propagation"); + ContextRegistry.getInstance().registerThreadLocalAccessor(new MdcPropagator()); + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcPropagator.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcPropagator.java new file mode 100644 index 0000000..75c40bc --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MdcPropagator.java @@ -0,0 +1,55 @@ +package com.sligrofoodgroup.sb.util.logging; + + +import io.micrometer.context.ThreadLocalAccessor; +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.slf4j.MDC; + +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +@Slf4j +class MdcPropagator implements ThreadLocalAccessor> { + public static final String MDC_TLA_NAME = MdcPropagator.class.getName(); + + @NotNull + public static Map getMdcContext() { + return Optional.ofNullable(MDC.getCopyOfContextMap()) + .map(Map::entrySet) + .orElse(Collections.emptySet()) + .stream() + .filter(e -> e.getKey().startsWith(AccessLogFilter.MDC_PREFIX)) + .filter(e -> Objects.nonNull(e.getValue())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + @Override + public @NotNull Object key() { + return MDC_TLA_NAME; + } + + @Override + @NotNull + public Map getValue() { + return getMdcContext(); + } + + @Override + public void setValue(@NotNull Map value) { + value.forEach(MDC::put); + } + + @Override + public void setValue() { + Optional.ofNullable(MDC.getCopyOfContextMap()) + .map(Map::keySet) + .orElse(Collections.emptySet()) + .stream() + .filter(key -> key.startsWith(AccessLogFilter.MDC_PREFIX)) + .forEach(MDC::remove); + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MissingMdcLoggingConfiguration.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MissingMdcLoggingConfiguration.java new file mode 100644 index 0000000..3ae15dd --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/MissingMdcLoggingConfiguration.java @@ -0,0 +1,16 @@ +package com.sligrofoodgroup.sb.util.logging; + +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConditionalOnMissingClass("io.micrometer.context.ContextRegistry") +class MissingMdcLoggingConfiguration { + @PostConstruct + public void registerMdcPropagation() { + log.warn("Missing Micrometer Context Propagator dependency, MDC is not propagated"); + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/ServletAccessLogFilter.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/ServletAccessLogFilter.java new file mode 100644 index 0000000..63de921 --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/ServletAccessLogFilter.java @@ -0,0 +1,39 @@ +package com.sligrofoodgroup.sb.util.logging; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.jetbrains.annotations.NotNull; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) +class ServletAccessLogFilter extends OncePerRequestFilter { + + private final AccessLogFilter accessLogFilterLogger = new AccessLogFilter(); + + @Override + protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) throws ServletException, IOException { + AccessLogFilter.AccessLogContex accessLogContex = accessLogFilterLogger.requestStart(new ServletServerHttpRequest(request)); + try { + filterChain.doFilter(request, response); + accessLogContex.requestEnd(HttpStatusCode.valueOf(response.getStatus())); + } catch (Exception throwable) { + accessLogContex.requestEnd(HttpStatusCode.valueOf(response.getStatus()), throwable); + throw throwable; + } finally { + accessLogFilterLogger.clearMdc(); + } + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebClientRequestIdForwarder.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebClientRequestIdForwarder.java new file mode 100644 index 0000000..72ee059 --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebClientRequestIdForwarder.java @@ -0,0 +1,28 @@ +package com.sligrofoodgroup.sb.util.logging; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.web.reactive.function.client.WebClientCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.ClientRequest; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@Configuration +@ConditionalOnClass(WebClient.class) +public class WebClientRequestIdForwarder { + + @Bean + public WebClientCustomizer webClientCustomizer() { + return webClientBuilder -> + webClientBuilder.filter(((request, next) -> + Mono.deferContextual((contextView -> + next.exchange(ClientRequest + .from(request) + .headers(httpHeaders -> { + contextView.getOrEmpty(AccessLogFilter.MDC_REQUEST_ID) + .ifPresent(requestId -> httpHeaders.set(AccessLogFilter.HTTP_HEADER_X_REQUEST_ID, (String) requestId)); + }) + .build()))))); + } +} diff --git a/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebFluxAccessLogFilter.java b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebFluxAccessLogFilter.java new file mode 100644 index 0000000..c030bc9 --- /dev/null +++ b/spring-boot-common-utils/src/main/java/com/sligrofoodgroup/sb/util/logging/WebFluxAccessLogFilter.java @@ -0,0 +1,38 @@ +package com.sligrofoodgroup.sb.util.logging; + +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; +import org.springframework.web.server.WebFilterChain; +import reactor.core.publisher.Mono; +import reactor.util.context.Context; + + +@Slf4j +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) +class WebFluxAccessLogFilter implements WebFilter { + + private final AccessLogFilter accessLogger = new AccessLogFilter(); + + @Override + public @NotNull Mono filter(@NotNull ServerWebExchange exchange, @NotNull WebFilterChain chain) { + final AccessLogFilter.AccessLogContex accessLogContex = this.accessLogger.requestStart(exchange.getRequest()); + Mono filteredChain = chain.filter(exchange) + .doOnError(throwable -> accessLogContex.requestEnd(exchange.getResponse().getStatusCode(), throwable)) + .doOnSuccess(v -> accessLogContex.requestEnd(exchange.getResponse().getStatusCode())) + .contextWrite(Context.of(this.accessLogger.getPropagationContext())); + this.accessLogger.clearMdc(); + return filteredChain; + // NOTE: clearing the MDC isn't really possible in reactive context + // doFinally is invoked at the end of the mono chain in the thread the mono gets resolved. + // This makes doFinally unable to clear the MDC. + // Furthermore, this thread could already be handling a new request at this point in time. + } +} diff --git a/spring-boot-common-utils/src/main/resources/application-sfg-shared.yml b/spring-boot-common-utils/src/main/resources/application-sfg-shared.yml new file mode 100644 index 0000000..128a440 --- /dev/null +++ b/spring-boot-common-utils/src/main/resources/application-sfg-shared.yml @@ -0,0 +1,23 @@ +logging: + level: + nl: + sligro: INFO + com: + sligrofoodgroup: INFO +spring: + reactor: + context-propagation: auto +--- +spring: + config: + activate: + on-profile: '!local' +logging: + structured: + format: + console: logstash +#--- +#spring: +# config: +# activate: +# on-profile: local diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml new file mode 100644 index 0000000..f00ce38 --- /dev/null +++ b/spring-boot-parent/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.5 + + + + com.sligrofoodgroup.spring-boot-common + spring-boot-parent + 1.0-SNAPSHOT + pom + + + ${project.version} + 17 + 17 + UTF-8 + + + + + + + com.sligrofoodgroup + lib-1 + ${sfg-sb-commons-version} + + + com.sligrofoodgroup.spring-boot-common + spring-boot-common-utils + ${sfg-sb-commons-version} + + + + + org.jetbrains + annotations + 24.1.0 + + + + +