Class TraceIdLoggingWebMvcInterceptor

java.lang.Object
com.google.cloud.spring.logging.TraceIdLoggingWebMvcInterceptor
All Implemented Interfaces:
org.springframework.web.servlet.HandlerInterceptor

public class TraceIdLoggingWebMvcInterceptor extends Object implements org.springframework.web.servlet.HandlerInterceptor
HandlerInterceptor that extracts the request trace ID from the "x-cloud-trace-context" HTTP header and stores it in a thread-local using TraceIdLoggingEnhancer.setCurrentTraceId(java.lang.String).

The TraceIdLoggingEnhancer can then be used in a logging appender to add the trace ID metadata to log messages.

  • Constructor Details

    • TraceIdLoggingWebMvcInterceptor

      public TraceIdLoggingWebMvcInterceptor(TraceIdExtractor extractor)
  • Method Details

    • getTraceIdExtractor

      public TraceIdExtractor getTraceIdExtractor()
    • preHandle

      public boolean preHandle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp, Object handler)
      Specified by:
      preHandle in interface org.springframework.web.servlet.HandlerInterceptor
    • afterCompletion

      public void afterCompletion(jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse, Object handler, Exception e)
      Specified by:
      afterCompletion in interface org.springframework.web.servlet.HandlerInterceptor