def _handler( servicer: "ArtifactManagerServicer", request: Union[BluePrintDownloadInput, BluePrintRemoveInput, BluePrintUploadInput], context: ServicerContext, ) -> BluePrintManagementOutput: try: output: BluePrintManagementOutput = func(servicer, request, context) output.status.code = 200 output.status.message = "success" except ArtifactManagerError as error: # If ArtifactManagerError is raises one of defined error occurs. # Every ArtifactManagerError based exception has status_code paramenter # which has to be set in output. Use also exception's message to # set errorMessage of the output. output: BluePrintManagementOutput = BluePrintManagementOutput() output.status.code = error.status_code output.status.message = "failure" output.status.errorMessage = str(error.message) servicer.fill_MDC_timestamps() servicer.logger.error( "Error while processing the message - blueprintName={} blueprintVersion={}" .format(request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion), extra={"mdc": MDC.result()}, ) MDC.clear() return output
def _decorator( servicer: "ArtifactManagerServicer", request: Union[BlueprintDownloadInput, BlueprintRemoveInput, BlueprintUploadInput], context: ServicerContext, ) -> BlueprintManagementOutput: MDC.put("RequestID", request.commonHeader.requestId) MDC.put("InvocationID", request.commonHeader.subRequestId) MDC.put("ServiceName", servicer.__class__.__name__) MDC.put("PartnerName", request.commonHeader.originatorId) started_at = datetime.utcnow().replace(tzinfo=timezone.utc) MDC.put("BeginTimestamp", started_at.strftime(MDC_DATETIME_FORMAT)) # Adding processing_started_at to the servicer so later we'll have the data to calculate elapsed time. servicer.processing_started_at = started_at MDC.put("TargetEntity", "py-executor") MDC.put("TargetServiceName", func.__name__) MDC.put("Server", socket.getfqdn()) output: BlueprintManagementOutput = func(servicer, request, context) MDC.clear() return output
def process_response(self, request, response): MDC.clear() return response
def process_response(self, response): ''' process response ''' MDC.clear() return response
def clear_mdc(): """Clear MDC """ MDC.clear()