Skip to content
Snippets Groups Projects
Commit f12e4387 authored by Sathyanarayanan Saravanamuthu's avatar Sathyanarayanan Saravanamuthu
Browse files

Merge branch 'sasarava/log1' into 'master'

Adding entries to requests table on notification processing

See merge request !181
parents 187cc82c fa57ebb7
No related branches found
No related tags found
3 merge requests!232Update os-core-lib-azure,!231initial commit,!181Adding entries to requests table on notification processing
Pipeline #93756 passed with warnings
......@@ -14,7 +14,10 @@
package org.opengroup.osdu.notification.provider.azure.messageBus;
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import com.microsoft.azure.servicebus.IMessage;
import org.apache.commons.lang3.time.StopWatch;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.notification.provider.azure.messageBus.thread.ThreadScopeContextHolder;
......@@ -29,6 +32,8 @@ import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.concurrent.ConcurrentMap;
import java.util.Date;
@Component
@ConditionalOnExpression("${azure.serviceBus.enabled:true} || ${azure.eventGridToServiceBus.enabled:true}")
......@@ -45,12 +50,20 @@ public class ProcessNotification {
private MDCContextMap mdcContextMap;
public void performNotification(IMessage message, String subscriptionName) throws Exception {
TelemetryClient telemetryClient = new TelemetryClient();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
NotificationContent notificationContent = requestBodyAdapter.extractNotificationContent(message, subscriptionName);
String dataPartitionId = notificationContent.getExtractAttributes().get(DpsHeaders.DATA_PARTITION_ID);
String correlationId = notificationContent.getExtractAttributes().get(DpsHeaders.CORRELATION_ID);
ConcurrentMap properties = telemetryClient.getContext().getProperties();
properties.put("correlation-id",correlationId);
properties.put("data-partition-id", dataPartitionId);
MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId));
dpsHeaders.setThreadContext(dataPartitionId, correlationId);
......@@ -58,15 +71,30 @@ public class ProcessNotification {
HttpResponse response = notificationHandler.notifySubscriber(notificationContent.getNotificationId(),
notificationContent.getData(), notificationContent.getExtractAttributes());
RequestTelemetry requestTelemetry = new RequestTelemetry(
"SBQueueRequest",
new Date(),
stopWatch.getTime(),
"500",
false);
requestTelemetry.setId(message.getMessageId());
if (!response.isSuccessCode()) {
telemetryClient.trackRequest(requestTelemetry);
throw new Exception(NOT_ACKNOWLEDGE);
}else{
requestTelemetry.setResponseCode("200");
requestTelemetry.setSuccess(true);
telemetryClient.trackRequest(requestTelemetry);
}
} catch (Exception e) {
LOGGER.error(String.format("An error occurred performing Notification for message with ID: ", message.getMessageId()), e);
LOGGER.error(String.format("An error occurred performing Notification for message with ID: ", message.getMessageId()), e);
throw e;
} finally {
ThreadScopeContextHolder.getContext().clear();
MDC.clear();
stopWatch.stop();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment