Skip to content

Latest commit

 

History

History
264 lines (178 loc) · 12.5 KB

APPENDIX_A.md

File metadata and controls

264 lines (178 loc) · 12.5 KB

APPENDIX A

NOTES

ASPECT LOGGING, STRUCTURED LOGGING and DISTRIBUTED TRACING

This StackOverflow question/thread demonstrates how hard the problem of combining LOGGING with DISTRIBUTED TRACING is, especially when you are using ASPECT ORIENTED PROGRAMMING (AOP) with Java and Spring Boot. Furthermore, this thread is only about logging all requests, things get really "fun", when you start adding DISTRIBUTED TRACING etc.

While you have many individual options for just one or the other, the difficulty arises when you try to combine them and make them play nice. I am referring to combining the following:

  • AOP (Controller Advice, ResponseBodyAdvice etc.)
  • Logging (cross-cutting concern => AOP)
  • SLF4J
  • MDC
  • Filters (Request/Responce Filters etc.)
  • Interceptors (Request/Responce Interceptors etc.)
  • Handlers (Exception Handlers etc.)
  • Servlets
  • Spring/Spring Boot Configuration
  • Dependencies
  • Java version

As you can see because of the amount of topics, and the amount of possible approaches for each topic, the amount of possible successful combinations grows exponentially small. It becomes almost as trying to find a needle in a haystack, as when you have just fixed or made two of them play nice together, the third next thing you need for the next functionality breaks one of the previous two.

Difficulties capturing Response body

RE: Here is one good alternative using ResponseBodyAdvice:

Difficulties with AOP and Controlelrs

RE: Spring AOP does not work when the request is not mapped or valid

Difficulties with injecting HttpServletRequest into a Spring AOP request

  • https://stackoverflow.com/questions/19271807/how-to-inject-httpservletrequest-into-a-spring-aop-request-custom-scenario And I quote:

    "Not easily. Actually, it would require a lot of effort.

    The easy way to do it is to rely on RequestContextHolder. In every request, the DispatcherServlet binds the current HttpServletRequest to a static ThreadLocal object in the RequestContextHolder. You can retrieve it when executing within the same Thread with

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); > You can do this in the advice() method and therefore don't need to declare a parameter."

Apsects Aspect Oriented Programming (AOP)

RE: AOP

RE: Aspect Weaving

RE: Logging Requests/Responses

Filters

RE: Difficulty injecting Request scope object into @Aspect

RE: Difficulty adding the traceId from Spring Cloud Sleuth to response in Filter

RE: Difficulty in ContentCachingResponseWrapper Produces Empty Response

RE: Here you can exclude urls, so the response does not get logged twice, once by doFilterInternal() and once by the Aspect.

RE: Bypassing the HttpServletRequest issue RE: Adding CachedBodyHttpServletRequest to Spring Boot Filter

RE: Filters/Filtering

Interceptors/Intercepting

RE: Exclude Spring Request HandlerInterceptor by Path-Pattern

RE: Interceptor

RE: Filter Interceptor Request Response Wrapping

Distributed Tracing

RE: Distributed Tracing

RE: Sleuth

RE: Zipkin

RE: Correlation in Logging; Mapped Diagnostic Context (MDC); Logback; Log4j2;

RE: A way to get traceId into an SLF4j MDC

Exception Handling

RE: Difficulty in missing errors

RE: Spring-Boot: Missing logs on HTTP 500

If you don't handle the exception at all then it will become an error dispatch, i.e. filters are executed a second time with the DispatcherType.ERROR trying to delegate to an error page. By default you don't get any from Spring, iirc.

Error dispatch is a tricky beast to get right, especially with Logbook. See #32, #155 and #334. Past experiences can be best summarized as Don't use ERROR dispatch.

Instead I'd suggest to use custom @ExceptionHandlers or something like https://github.com/zalando/problem-spring-web.

RE: Problems for Spring MVC and Spring WebFlux

RE: Customize HTTP Error Responses in Spring Boot

RE: Spring Boot Exception Handling for REST and MVC

RE: Error Handling for REST with Spring

Structured Logging

RE: Logback + Logstash + Configuration

RE: Logging in JSON general

RE: JSON Logging for Spring Boot + Logstash

RE: Structured Logging

Maven

RE: Maven Enforcer Plugin

RE:--illegal-access=deny RE: Illegal reflective access

Spring application.properties

RE: spring.jpa.open-in-view Warning

Design Patterns

Docker & Docker-compose