Skip to content

Commit

Permalink
fix(logging): Correctly propagate stage IDs for logging (#2847)
Browse files Browse the repository at this point in the history
Currently, the stageID isn't sent over when we make e.g. clouddriver calls.
This makes tracing operation of a given stage VERY difficult.
Add stageIDs to the MDC context for propagation with HTTP headers
  • Loading branch information
marchello2000 authored Apr 18, 2019
1 parent ca1a526 commit 76fa777
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.netflix.spinnaker.orca.q.audit

import com.netflix.spinnaker.orca.q.ExecutionLevel
import com.netflix.spinnaker.orca.q.StageLevel
import com.netflix.spinnaker.orca.q.TaskLevel
import com.netflix.spinnaker.q.Message
import com.netflix.spinnaker.q.MessageHandler
import com.netflix.spinnaker.security.AuthenticatedRequest.SPINNAKER_EXECUTION_ID
Expand All @@ -41,9 +43,18 @@ class ExecutionTrackingMessageHandlerPostProcessor : BeanPostProcessor {
) : MessageHandler<M> by delegate {
override fun invoke(message: Message) {
try {
if (message is ExecutionLevel) {
MDC.put(SPINNAKER_EXECUTION_ID, message.executionId)
when(message) {
is TaskLevel -> {
MDC.put(SPINNAKER_EXECUTION_ID, "${message.executionId}:${message.stageId}:${message.taskId}")
}
is StageLevel -> {
MDC.put(SPINNAKER_EXECUTION_ID, "${message.executionId}:${message.stageId}")
}
is ExecutionLevel -> {
MDC.put(SPINNAKER_EXECUTION_ID, message.executionId)
}
}

delegate.invoke(message)
} finally {
MDC.remove(SPINNAKER_EXECUTION_ID)
Expand Down

0 comments on commit 76fa777

Please sign in to comment.