You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by st...@apache.org on 2023/11/16 22:49:39 UTC
(solr) branch branch_9x updated: SOLR-17035 Add trace id to jetty thread names to improve debuggability (#2019)
This is an automated email from the ASF dual-hosted git repository.
stillalex pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 598600dafe2 SOLR-17035 Add trace id to jetty thread names to improve debuggability (#2019)
598600dafe2 is described below
commit 598600dafe2d637cdcca7cdc0068ba5bf09c1ac1
Author: Alex D <st...@apache.org>
AuthorDate: Thu Nov 16 14:22:35 2023 -0800
SOLR-17035 Add trace id to jetty thread names to improve debuggability (#2019)
---
solr/CHANGES.txt | 2 ++
solr/core/src/java/org/apache/solr/servlet/ServletUtils.java | 10 +++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 54f002e8a10..578bccc4589 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -34,6 +34,8 @@ Improvements
* SOLR-16397: The rename-core v2 endpoint has been updated to be more REST-ful.
RENAME is now available at `POST /api/cores/coreName/rename` (Sanjay Dutt via Jason Gerlowski)
+* SOLR-17035: Add trace id to jetty thread names to improve debuggability via stack traces (Alex Deparvu)
+
Optimizations
---------------------
(No changes)
diff --git a/solr/core/src/java/org/apache/solr/servlet/ServletUtils.java b/solr/core/src/java/org/apache/solr/servlet/ServletUtils.java
index a286078dafb..49611c929f7 100644
--- a/solr/core/src/java/org/apache/solr/servlet/ServletUtils.java
+++ b/solr/core/src/java/org/apache/solr/servlet/ServletUtils.java
@@ -236,13 +236,16 @@ public abstract class ServletUtils {
throws ServletException, IOException {
Tracer tracer = getTracer(request);
Span span = buildSpan(tracer, request);
-
+ final Thread currentThread = Thread.currentThread();
+ final String oldThreadName = currentThread.getName();
request.setAttribute(SolrDispatchFilter.ATTR_TRACING_SPAN, span);
try (var scope = tracer.scopeManager().activate(span)) {
-
assert scope != null; // prevent javac warning about scope being unused
MDCLoggingContext.setTracerId(span.context().toTraceId()); // handles empty string
-
+ String traceId = MDCLoggingContext.getTraceId();
+ if (traceId != null) {
+ currentThread.setName(oldThreadName + "-" + traceId);
+ }
tracedExecution.run();
} catch (ExceptionWhileTracing e) {
if (e.e instanceof SolrAuthenticationException) {
@@ -261,6 +264,7 @@ public abstract class ServletUtils {
throw new RuntimeException(e.e);
}
} finally {
+ currentThread.setName(oldThreadName);
span.setTag(Tags.HTTP_STATUS, response.getStatus());
span.finish();
}