From a768904e4ea1c8498e7fa6e4df0353e090f4d02a Mon Sep 17 00:00:00 2001 From: Rick Parker Date: Thu, 28 Jun 2018 11:24:54 +0100 Subject: [PATCH] CORDA-1695 Include thread ID in flow logging MDC (#3463) --- .../node/services/statemachine/FlowStateMachineImpl.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt index b38ca474ab..04e73648b3 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt @@ -108,19 +108,21 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, if (value) field = value else throw IllegalArgumentException("Can only set to true") } - /** + /** * Processes an event by creating the associated transition and executing it using the given executor. * Try to avoid using this directly, instead use [processEventsUntilFlowIsResumed] or [processEventImmediately] * instead. */ @Suspendable private fun processEvent(transitionExecutor: TransitionExecutor, event: Event): FlowContinuation { + setLoggingContext() val stateMachine = getTransientField(TransientValues::stateMachine) val oldState = transientState!!.value val actionExecutor = getTransientField(TransientValues::actionExecutor) val transition = stateMachine.transition(event, oldState) val (continuation, newState) = transitionExecutor.executeTransition(this, oldState, event, transition, actionExecutor) transientState = TransientReference(newState) + setLoggingContext() return continuation } @@ -196,6 +198,7 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, context.pushToLoggingContext() MDC.put("flow-id", id.uuid.toString()) MDC.put("fiber-id", this.getId().toString()) + MDC.put("thread-id", Thread.currentThread().id.toString()) } @Suspendable @@ -353,6 +356,7 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, val serializationContext = TransientReference(getTransientField(TransientValues::checkpointSerializationContext)) val transaction = extractThreadLocalTransaction() parkAndSerialize { _, _ -> + setLoggingContext() logger.trace { "Suspended on $ioRequest" } // Will skip checkpoint if there are any idempotent flows in the subflow stack. @@ -379,7 +383,6 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, require(continuation == FlowContinuation.ProcessEvents) unpark(SERIALIZER_BLOCKER) } - setLoggingContext() return uncheckedCast(processEventsUntilFlowIsResumed( isDbTransactionOpenOnEntry = false, isDbTransactionOpenOnExit = true