Skip to content

Commit 8534d42

Browse files
committed
HBASE-27762 Include EventType and ProcedureV2 pid in logging via MDC
1 parent a6dad70 commit 8534d42

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

conf/log4j2.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ appender.console.type = Console
2525
appender.console.target = SYSTEM_ERR
2626
appender.console.name = console
2727
appender.console.layout.type = PatternLayout
28-
appender.console.layout.pattern = %d{ISO8601} %-5p [%t] %c{2}: %.1000m%n
28+
appender.console.layout.pattern = %d{ISO8601} %-5p [%t (%X)] %c{2}: %.1000m%n
2929

3030
# Daily Rolling File Appender
3131
appender.DRFA.type = RollingFile

hbase-logging/src/test/resources/log4j2.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ appender.console.target = SYSTEM_ERR
2626
appender.console.name = Console
2727
appender.console.maxSize = 1G
2828
appender.console.layout.type = PatternLayout
29-
appender.console.layout.pattern = %d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
29+
appender.console.layout.pattern = %d{ISO8601} %-5p [%t (%X)] %C{2}(%L): %m%n
3030

3131
rootLogger = INFO,Console
3232

hbase-server/src/main/java/org/apache/hadoop/hbase/executor/EventHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.yetus.audience.InterfaceAudience;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
30+
import org.slf4j.MDC;
3031

3132
/**
3233
* Abstract base class for all HBase event handlers. Subclasses should implement the
@@ -96,6 +97,10 @@ public EventHandler prepare() throws Exception {
9697
public void run() {
9798
Span span = TraceUtil.getGlobalTracer().spanBuilder(getClass().getSimpleName())
9899
.setParent(Context.current().with(parent)).startSpan();
100+
// assume that this is the top of an execution on a new or reused thread, that we're safe to
101+
// blast any existing MDC state.
102+
MDC.clear();
103+
MDC.put("event_type", eventType.toString());
99104
try (Scope scope = span.makeCurrent()) {
100105
process();
101106
} catch (Throwable t) {

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/RSProcedureHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.yetus.audience.InterfaceAudience;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26+
import org.slf4j.MDC;
2627

2728
/**
2829
* A event handler for running procedure.
@@ -46,6 +47,7 @@ public RSProcedureHandler(HRegionServer rs, long procId, RSProcedureCallable cal
4647
public void process() {
4748
Throwable error = null;
4849
try {
50+
MDC.put("pid", Long.toString(procId));
4951
callable.call();
5052
} catch (Throwable t) {
5153
LOG.error("pid=" + this.procId, t);

0 commit comments

Comments
 (0)