From 761966387b76b5f374d12197929831ae7fef6e17 Mon Sep 17 00:00:00 2001 From: JiviteshT <112479261+JiviteshT@users.noreply.github.com> Date: Mon, 16 Oct 2023 19:13:30 +0100 Subject: [PATCH] Abzu-97705-Moved Apm transaction code from program to fulfilment service job class. (#235) --- NVDSuppressions.xml | 9 +++ .../FulfilmentServiceJob.cs | 59 ++++++++++++------- .../Program.cs | 15 ++--- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/NVDSuppressions.xml b/NVDSuppressions.xml index 26d605303..e651f33fa 100644 --- a/NVDSuppressions.xml +++ b/NVDSuppressions.xml @@ -322,4 +322,13 @@ CVE-2021-37941 CVE-2019-7617 + + + + + ^pkg:nuget/Azure\.Identity@.*$ + CVE-2023-36414 + diff --git a/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/FulfilmentServiceJob.cs b/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/FulfilmentServiceJob.cs index e6ec02a3f..b65d9662d 100644 --- a/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/FulfilmentServiceJob.cs +++ b/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/FulfilmentServiceJob.cs @@ -7,6 +7,8 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; +using Elastic.Apm; +using Elastic.Apm.Api; using UKHO.ExchangeSetService.Common.Configuration; using UKHO.ExchangeSetService.Common.Extensions; using UKHO.ExchangeSetService.Common.Helpers; @@ -68,28 +70,37 @@ public async Task ProcessQueueMessage([QueueTrigger("%ESSFulfilmentStorageConfig logger.LogInformation(EventIds.AIOToggleIsOff.ToEventId(), "ESS Webjob : AIO toggle is OFF for BatchId:{BatchId} | _X-Correlation-ID : {CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } - if (CommonHelper.IsPeriodicOutputService) - { - await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateLargeExchangeSetRequestStart, - EventIds.CreateLargeExchangeSetRequestCompleted, - "Create Large Exchange Set web job request for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", - async () => - { - return await fulFilmentDataService.CreateLargeExchangeSet(fulfilmentServiceQueueMessage, currentUtcDate, periodicOutputServiceConfiguration.Value.LargeExchangeSetFolderName); - }, - fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); - } - else + string transactionName = + $"{System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")}-fulfilment-transaction"; + + await Agent.Tracer.CaptureTransaction(transactionName, ApiConstants.TypeRequest, async () => { - await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateExchangeSetRequestStart, - EventIds.CreateExchangeSetRequestCompleted, - "Create Exchange Set web job request for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", - async () => - { - return await fulFilmentDataService.CreateExchangeSet(fulfilmentServiceQueueMessage, currentUtcDate); - }, - fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); - } + if (CommonHelper.IsPeriodicOutputService) + { + await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateLargeExchangeSetRequestStart, + EventIds.CreateLargeExchangeSetRequestCompleted, + "Create Large Exchange Set web job request for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", + async () => + { + return await fulFilmentDataService.CreateLargeExchangeSet(fulfilmentServiceQueueMessage, + currentUtcDate, + periodicOutputServiceConfiguration.Value.LargeExchangeSetFolderName); + }, + fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); + } + else + { + await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateExchangeSetRequestStart, + EventIds.CreateExchangeSetRequestCompleted, + "Create Exchange Set web job request for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", + async () => + { + return await fulFilmentDataService.CreateExchangeSet(fulfilmentServiceQueueMessage, + currentUtcDate); + }, + fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); + } + }); } catch (Exception ex) { @@ -105,6 +116,12 @@ await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateExchangeSetRequestSta if (ex.GetType() != typeof(FulfilmentException)) logger.LogError(exceptionEventId, ex, "Unhandled exception while processing Exchange Set web job for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId, ex.Message); + + Agent.Tracer.CurrentTransaction?.CaptureException(ex); + } + finally + { + Agent.Tracer.CurrentTransaction?.End(); } } diff --git a/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/Program.cs b/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/Program.cs index 6a06915dc..1289db300 100644 --- a/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/Program.cs +++ b/UKHO.ExchangeSetService.API/UKHO.ExchangeSetService.FulfilmentService/Program.cs @@ -26,11 +26,9 @@ using Microsoft.ApplicationInsights.Extensibility; using UKHO.ExchangeSetService.FulfilmentService.Filters; using UKHO.ExchangeSetService.FulfilmentService.Validation; -using System.Collections.Generic; using Elastic.Apm.Azure.Storage; using Elastic.Apm.DiagnosticSource; using Elastic.Apm; -using Elastic.Apm.Api; namespace UKHO.ExchangeSetService.FulfilmentService { @@ -49,16 +47,11 @@ public static void Main(string[] args) HostBuilder hostBuilder = BuildHostConfiguration(); IHost host = hostBuilder.Build(); - string transactionName = $"{System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")}-fulfilment-transaction"; - - Agent.Tracer.CaptureTransaction(transactionName, ApiConstants.TypeRequest, () => + + using (host) { - using (host) - { - host.Run(); - } - }); - + host.Run(); + } } private static HostBuilder BuildHostConfiguration() {