-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-5208 Enable request tracing through logs using new associated request id #5209
GH-5208 Enable request tracing through logs using new associated request id #5209
Conversation
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also used MDC for this in other dev projects. It's probably still the best option.
From experience it can get quite expensive to generate a lot of UUIDs especially if the transactions are very small. Can we have the UUID as a string at startup and then an AtomicLong that we increment and append?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Should be changed. Introduced a process UUID which is postpended with an AtomicLong
in a format which should be parsable by some tooling if need be.
Let me know your thoughts.
@@ -24,13 +28,23 @@ | |||
*/ | |||
public abstract class ServerInterceptor implements HandlerInterceptor { | |||
|
|||
private static final String REQUEST_ID_KEY = "requestId"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having some second doubts about the naming. We have users that extend the RDF4J server code and it could be that they are already doing something similar to this. Do you think we could call ours rdf4jRequestId
just to be sure that we don't overwrite someone else's request ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh fair point. I've also seen the package name convention used. Something like org.eclipse.rdf4j.requestId
so there would never be the possibility of a clash unless we did it to ourselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package name looks very nice!
…sociated request id
bb63f00
to
222760e
Compare
GitHub issue resolved: #5208
Briefly describe the changes proposed in this PR:
This PR adds a unique request identifier to MDC in order to allow for more intelligent log parsing and aggregation as well as aid in server debugging.
PR Author Checklist (see the contributor guidelines for more details):
mvn process-resources
to format from the command line)