From be4b713c7bd80ac0ac98f3f1ea8bc8f477dcb3e2 Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Tue, 7 Jun 2022 19:30:54 -0400 Subject: Improve log format consistency Logs related to request processing should include: requestId, subrequestId and originatorId. Each API (rest,grpc,kafka) would produce different outputs, due to MDC context not being passed properly between coroutine contexts or values not being populated. Issue-ID: CCSDK-3686 Signed-off-by: Jozsef Csongvai Change-Id: Ibafdffd3409b9724ad91633ca5840070f7e287f5 --- .../grpc/service/GrpcLoggerService.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ms/blueprintsprocessor/modules/commons/grpc-lib') diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt index 732f4fecf..987ac447a 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt @@ -20,6 +20,10 @@ import io.grpc.Grpc import io.grpc.Metadata import io.grpc.ServerCall import io.grpc.ServerCallHandler +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.newCoroutineContext +import kotlinx.coroutines.withContext import org.onap.ccsdk.cds.blueprintsprocessor.grpc.getStringKey import org.onap.ccsdk.cds.blueprintsprocessor.grpc.putStringKeyValue import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader @@ -28,9 +32,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVO import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.MDCContext import org.onap.ccsdk.cds.controllerblueprints.core.defaultToEmpty import org.onap.ccsdk.cds.controllerblueprints.core.defaultToUUID import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput import org.slf4j.MDC import java.net.InetAddress import java.net.InetSocketAddress @@ -108,3 +114,16 @@ class GrpcLoggerService { } } } +suspend fun mdcGrpcCoroutineScope( + executionServiceInput: ExecutionServiceInput, + block: suspend CoroutineScope.() -> T +) = coroutineScope { + + MDC.put("RequestID", executionServiceInput.commonHeader.requestId) + MDC.put("SubRequestID", executionServiceInput.commonHeader.subRequestId) + MDC.put("OriginatorID", executionServiceInput.commonHeader.originatorId) + + withContext(newCoroutineContext(this.coroutineContext + MDCContext(MDC.getCopyOfContextMap()))) { + block() + } +} -- cgit 1.2.3-korg