Skip to content

Commit f2e113a

Browse files
Adding attempt number into MDC context for better diagnosing (#2193)
1 parent 4eaeb9e commit f2e113a

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

temporal-sdk/src/main/java/io/temporal/internal/logging/LoggerTag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ private LoggerTag() {}
3737
public static final String WORKER_TYPE = "WorkerType";
3838
public static final String SIDE_EFFECT_ID = "SideEffectId";
3939
public static final String CHILD_WORKFLOW_ID = "ChildWorkflowId";
40+
public static final String ATTEMPT = "Attempt";
4041
}

temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public void handle(ActivityTask task) throws Exception {
247247
MDC.put(LoggerTag.WORKFLOW_ID, pollResponse.getWorkflowExecution().getWorkflowId());
248248
MDC.put(LoggerTag.WORKFLOW_TYPE, pollResponse.getWorkflowType().getName());
249249
MDC.put(LoggerTag.RUN_ID, pollResponse.getWorkflowExecution().getRunId());
250+
MDC.put(LoggerTag.ATTEMPT, Integer.toString(pollResponse.getAttempt()));
250251

251252
ActivityTaskHandler.Result result = null;
252253
try {
@@ -257,6 +258,7 @@ public void handle(ActivityTask task) throws Exception {
257258
MDC.remove(LoggerTag.WORKFLOW_ID);
258259
MDC.remove(LoggerTag.WORKFLOW_TYPE);
259260
MDC.remove(LoggerTag.RUN_ID);
261+
MDC.remove(LoggerTag.ATTEMPT);
260262
if (
261263
// handleActivity throw an exception (not a normal scenario)
262264
result == null

temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ public void handle(LocalActivityAttemptTask attemptTask) throws Exception {
441441
MDC.put(LoggerTag.WORKFLOW_ID, activityTask.getWorkflowExecution().getWorkflowId());
442442
MDC.put(LoggerTag.WORKFLOW_TYPE, activityTask.getWorkflowType().getName());
443443
MDC.put(LoggerTag.RUN_ID, activityTask.getWorkflowExecution().getRunId());
444+
MDC.put(LoggerTag.ATTEMPT, Integer.toString(activityTask.getAttempt()));
444445

445446
slotSupplier.markSlotUsed(
446447
new LocalActivitySlotInfo(
@@ -506,6 +507,7 @@ public void handle(LocalActivityAttemptTask attemptTask) throws Exception {
506507
MDC.remove(LoggerTag.WORKFLOW_ID);
507508
MDC.remove(LoggerTag.WORKFLOW_TYPE);
508509
MDC.remove(LoggerTag.RUN_ID);
510+
MDC.remove(LoggerTag.ATTEMPT);
509511
}
510512
}
511513

0 commit comments

Comments
 (0)