Skip to content

Commit

Permalink
eclipse-rdf4jGH-5208 Enable request tracing through logs using new as…
Browse files Browse the repository at this point in the history
…sociated request id
  • Loading branch information
bherber1 committed Nov 26, 2024
1 parent 6e64a12 commit e22e99d
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
*******************************************************************************/
package org.eclipse.rdf4j.http.server;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.MDC;
import org.springframework.web.servlet.HandlerInterceptor;

/**
Expand All @@ -24,13 +27,15 @@
*/
public abstract class ServerInterceptor implements HandlerInterceptor {

private static final String REQUEST_ID = "requestId";
private volatile String origThreadName;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
origThreadName = Thread.currentThread().getName();
Thread.currentThread().setName(getThreadName());
MDC.put(REQUEST_ID, UUID.randomUUID().toString());

setRequestAttributes(request);

Expand All @@ -43,6 +48,7 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp
try {
cleanUpResources();
} finally {
MDC.remove(REQUEST_ID);
Thread.currentThread().setName(origThreadName);
}
}
Expand Down

0 comments on commit e22e99d

Please sign in to comment.