Introduce Instrumentation
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / event / lcm / LcmEventsService.java
index 762b21e..a94d664 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.cps.ncmp.api.impl.event.lcm;
 
+import io.micrometer.core.annotation.Timed;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.ncmp.cmhandle.event.lcm.LcmEvent;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.kafka.KafkaException;
 import org.springframework.stereotype.Service;
 
 /**
@@ -49,9 +51,15 @@ public class LcmEventsService {
      * @param cmHandleId Cm Handle Id
      * @param lcmEvent  Lcm Event
      */
+    @Timed(value = "cps.ncmp.lcm.events.publish",
+        description = "Time taken to publish a LCM event")
     public void publishLcmEvent(final String cmHandleId, final LcmEvent lcmEvent) {
         if (notificationsEnabled) {
-            lcmEventsPublisher.publishEvent(topicName, cmHandleId, lcmEvent);
+            try {
+                lcmEventsPublisher.publishEvent(topicName, cmHandleId, lcmEvent);
+            } catch (final KafkaException e) {
+                log.error("Unable to publish message to topic : {} and cause : {}", topicName, e.getMessage());
+            }
         } else {
             log.debug("Notifications disabled.");
         }