From ed10f71dca8983815818866bbecc69c9b66528d4 Mon Sep 17 00:00:00 2001 From: Phoebe Revolta Date: Thu, 6 Mar 2025 15:30:38 +0000 Subject: [PATCH 1/2] S28-3541: add AppInsights dependency to import telemetry, add to all changes in capture session status --- build.gradle | 1 + .../preapi/controllers/MediaServiceController.java | 5 +++++ .../reform/preapi/services/CaptureSessionService.java | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/build.gradle b/build.gradle index 284b9e7096..7519bbfdbc 100644 --- a/build.gradle +++ b/build.gradle @@ -263,6 +263,7 @@ ext.libraries = [ ext['snakeyaml.version'] = '2.0' dependencies { + implementation 'com.microsoft.azure:applicationinsights-core:3.7.1' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop' diff --git a/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java b/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java index 5c95dcdd86..818dc68412 100644 --- a/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java +++ b/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.preapi.controllers; import com.azure.resourcemanager.mediaservices.models.JobState; +import com.microsoft.applicationinsights.TelemetryClient; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; @@ -57,6 +58,8 @@ public class MediaServiceController extends PreApiController { private final AzureIngestStorageService azureIngestStorageService; private final RecordingService recordingService; + private final TelemetryClient telemetry = new TelemetryClient(); + @Autowired public MediaServiceController(MediaServiceBroker mediaServiceBroker, CaptureSessionService captureSessionService, @@ -243,6 +246,8 @@ public ResponseEntity createLiveEventStreamingLocator(@PathVa // update captureSession captureSession.setLiveOutputUrl(liveOutputUrl); captureSession.setStatus(RecordingStatus.RECORDING); + telemetry.trackEvent(captureSession.getStatus().name()); + captureSessionService.upsert(captureSession); return ResponseEntity.ok(captureSession); diff --git a/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java b/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java index c041a8afcc..e8110cfe1b 100644 --- a/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java +++ b/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.preapi.services; +import com.microsoft.applicationinsights.TelemetryClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -43,6 +44,8 @@ public class CaptureSessionService { private final UserRepository userRepository; private final BookingService bookingService; + private final TelemetryClient telemetry = new TelemetryClient(); + @Autowired public CaptureSessionService(RecordingService recordingService, CaptureSessionRepository captureSessionRepository, @@ -204,6 +207,7 @@ public UpsertResult upsert(CreateCaptureSessionDTO createCaptureSessionDTO) { captureSession.setFinishedAt(createCaptureSessionDTO.getFinishedAt()); captureSession.setFinishedByUser(finishedByUser); captureSession.setStatus(createCaptureSessionDTO.getStatus()); + telemetry.trackEvent(captureSession.getStatus().name()); captureSessionRepository.save(captureSession); @@ -237,6 +241,8 @@ public CaptureSessionDTO startCaptureSession(UUID id, RecordingStatus status, St captureSession.setStartedAt(Timestamp.from(Instant.now())); captureSession.setStatus(status); + telemetry.trackEvent(captureSession.getStatus().name()); + captureSession.setIngestAddress(ingestAddress); captureSessionRepository.save(captureSession); @@ -253,6 +259,8 @@ public CaptureSessionDTO stopCaptureSession(UUID captureSessionId, log.info("Stopping capture session {} with status {}", captureSessionId, status); captureSession.setStatus(status); + telemetry.trackEvent(captureSession.getStatus().name()); + switch (status) { case PROCESSING -> { @@ -283,6 +291,8 @@ public CaptureSessionDTO setCaptureSessionStatus(UUID captureSessionId, Recordin .findByIdAndDeletedAtIsNull(captureSessionId) .orElseThrow(() -> new NotFoundException("Capture Session: " + captureSessionId)); captureSession.setStatus(status); + telemetry.trackEvent(captureSession.getStatus().name()); + captureSessionRepository.save(captureSession); return new CaptureSessionDTO(captureSession); } From 34b2b83eef9a3e7de0017fefd5b582efd63fc1f1 Mon Sep 17 00:00:00 2001 From: Phoebe Revolta Date: Thu, 6 Mar 2025 16:03:38 +0000 Subject: [PATCH 2/2] S28-3541: add more detail to event tracker --- .../controllers/MediaServiceController.java | 7 +++++- .../services/CaptureSessionService.java | 23 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java b/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java index 818dc68412..54891d3c32 100644 --- a/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java +++ b/src/main/java/uk/gov/hmcts/reform/preapi/controllers/MediaServiceController.java @@ -43,7 +43,9 @@ import uk.gov.hmcts.reform.preapi.services.CaptureSessionService; import uk.gov.hmcts.reform.preapi.services.RecordingService; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.logging.Logger; @@ -246,7 +248,10 @@ public ResponseEntity createLiveEventStreamingLocator(@PathVa // update captureSession captureSession.setLiveOutputUrl(liveOutputUrl); captureSession.setStatus(RecordingStatus.RECORDING); - telemetry.trackEvent(captureSession.getStatus().name()); + Map properties = new HashMap(); + properties.put("captureSession_ID", captureSession.getId().toString()); + properties.put("captureSession_STATUS", captureSession.getStatus().name()); + telemetry.trackEvent(properties.toString()); captureSessionService.upsert(captureSession); diff --git a/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java b/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java index e8110cfe1b..fb22242b10 100644 --- a/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java +++ b/src/main/java/uk/gov/hmcts/reform/preapi/services/CaptureSessionService.java @@ -31,6 +31,8 @@ import java.sql.Timestamp; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -207,7 +209,10 @@ public UpsertResult upsert(CreateCaptureSessionDTO createCaptureSessionDTO) { captureSession.setFinishedAt(createCaptureSessionDTO.getFinishedAt()); captureSession.setFinishedByUser(finishedByUser); captureSession.setStatus(createCaptureSessionDTO.getStatus()); - telemetry.trackEvent(captureSession.getStatus().name()); + Map properties = new HashMap(); + properties.put("captureSession_ID", captureSession.getId().toString()); + properties.put("captureSession_STATUS", captureSession.getStatus().name()); + telemetry.trackEvent(properties.toString()); captureSessionRepository.save(captureSession); @@ -241,7 +246,10 @@ public CaptureSessionDTO startCaptureSession(UUID id, RecordingStatus status, St captureSession.setStartedAt(Timestamp.from(Instant.now())); captureSession.setStatus(status); - telemetry.trackEvent(captureSession.getStatus().name()); + Map properties = new HashMap(); + properties.put("captureSession_ID", captureSession.getId().toString()); + properties.put("captureSession_STATUS", captureSession.getStatus().name()); + telemetry.trackEvent(properties.toString()); captureSession.setIngestAddress(ingestAddress); @@ -259,8 +267,10 @@ public CaptureSessionDTO stopCaptureSession(UUID captureSessionId, log.info("Stopping capture session {} with status {}", captureSessionId, status); captureSession.setStatus(status); - telemetry.trackEvent(captureSession.getStatus().name()); - + Map properties = new HashMap(); + properties.put("captureSession_ID", captureSession.getId().toString()); + properties.put("captureSession_STATUS", captureSession.getStatus().name()); + telemetry.trackEvent(properties.toString()); switch (status) { case PROCESSING -> { @@ -291,7 +301,10 @@ public CaptureSessionDTO setCaptureSessionStatus(UUID captureSessionId, Recordin .findByIdAndDeletedAtIsNull(captureSessionId) .orElseThrow(() -> new NotFoundException("Capture Session: " + captureSessionId)); captureSession.setStatus(status); - telemetry.trackEvent(captureSession.getStatus().name()); + Map properties = new HashMap(); + properties.put("captureSession_ID", captureSession.getId().toString()); + properties.put("captureSession_STATUS", captureSession.getStatus().name()); + telemetry.trackEvent(properties.toString()); captureSessionRepository.save(captureSession); return new CaptureSessionDTO(captureSession);