Skip to content

Instantly share code, notes, and snippets.

@radutoev
Last active August 29, 2017 10:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save radutoev/110d782438a901742741d77e59afc697 to your computer and use it in GitHub Desktop.
Add correlation id on log4j's ThreadContext
public class CorrelationIdFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String correlationId = ((HttpServletRequest) request).getHeader("x-correlation-id");
ThreadContext.put("correlationId", correlationId);
try {
chain.doFilter(request, response);
} finally {
ThreadContext.clearAll();
}
}
@Override
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment