From 56646f9f7718efbf4ec8523adac30de0cea875ba Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Wed, 6 Nov 2024 10:16:48 +0000 Subject: [PATCH 1/2] PI-2584 Don't log if no messages received --- .../uk/gov/justice/digital/hmpps/service/MailboxService.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/MailboxService.kt b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/MailboxService.kt index e9fcb0e19e..5010ce1716 100644 --- a/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/MailboxService.kt +++ b/projects/justice-email-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/MailboxService.kt @@ -23,6 +23,7 @@ class MailboxService( @WithSpan("POLL mailbox", kind = SpanKind.SERVER) fun publishUnreadMessagesToQueue() { getUnreadMessages() + .ifEmpty { return } .also { telemetryService.trackEvent("ReceivedMessages", mapOf("count" to it.size.toString())) } .forEach { notificationPublisher.publish(it.asNotification()) From d4a5cf608de97190a03dd7e1487b19c3da80f04b Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Wed, 6 Nov 2024 10:22:42 +0000 Subject: [PATCH 2/2] Remove automated logging of published messages --- .../uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt | 3 +-- .../uk/gov/justice/digital/hmpps/publisher/TopicPublisher.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt index fbd7e244e0..645be2b628 100644 --- a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt +++ b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import io.awspring.cloud.sqs.operations.SqsTemplate import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.instrumentation.annotations.SpanAttribute import io.opentelemetry.instrumentation.annotations.WithSpan import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty @@ -30,7 +29,7 @@ class QueuePublisher( private val permit = Semaphore(limit, true) @WithSpan(kind = SpanKind.PRODUCER) - override fun publish(@SpanAttribute notification: Notification<*>) { + override fun publish(notification: Notification<*>) { Span.current().updateName("PUBLISH ${notification.eventType}").setAttribute("queue", queue) notification.message?.also { _ -> permit.acquire() diff --git a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/TopicPublisher.kt b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/TopicPublisher.kt index f841489575..e8e8d3cb29 100644 --- a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/TopicPublisher.kt +++ b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/TopicPublisher.kt @@ -3,7 +3,6 @@ package uk.gov.justice.digital.hmpps.publisher import io.awspring.cloud.sns.core.SnsTemplate import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.instrumentation.annotations.SpanAttribute import io.opentelemetry.instrumentation.annotations.WithSpan import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty @@ -25,7 +24,7 @@ class TopicPublisher( @Value("\${messaging.producer.topic}") private val topic: String ) : NotificationPublisher { @WithSpan(kind = SpanKind.PRODUCER) - override fun publish(@SpanAttribute notification: Notification<*>) { + override fun publish(notification: Notification<*>) { Span.current().updateName("PUBLISH ${notification.eventType}").setAttribute("topic", topic) notification.message?.let { message -> notificationTemplate.convertAndSend(topic, message) { msg ->