Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releases/0.3.2 add logs #418

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class NotificationEventServiceDefault implements NotificationEventService

public static final String EVENT_ONBOARDING_FN_NAME = "ONBOARDING-FN";
public static final String EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE = "EventsOnboardingInstitution_failures";
public static final String EVENT_ONBOARDING_INSTTITUTION_FN_ERROR = "EventsOnboardingInstitution_error";
public static final String EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS = "EventsOnboardingInstitution_success";
public static final String OPERATION_NAME = "ONBOARDING-FN";
private final TelemetryClient telemetryClient;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que
prepareAndSendNotification(context, product, consumerConfig, onboarding, token.orElse(null), institution, queueEvent);
}
} catch (Exception e) {
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, onboardingEventMap(onboarding), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE, 1D));
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, onboardingEventMap(onboarding), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_ERROR, 1D));
context.getLogger().severe(String.format("Impossible to send notification for onboarding with ID %s %s", onboarding.getId(), Arrays.toString(e.getStackTrace())));
throw new NotificationException(String.format("Impossible to send notification for onboarding with ID %s", onboarding.getId()), e);
}
}
Expand All @@ -120,9 +122,9 @@ private void sendNotification(ExecutionContext context, String topic, Notificati

try {
eventHubRestClient.sendMessage(topic, message);
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D));
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D));
} catch (Exception e) {
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE, 1D));
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE, 1D));
throw new NotificationException(e.getMessage());
}
}
Expand All @@ -144,8 +146,9 @@ public static Map<String, String> onboardingEventMap(Onboarding onboarding) {
return propertiesMap;
}

public static Map<String, String> notificationEventMap(NotificationToSend notificationToSend) {
public static Map<String, String> notificationEventMap(NotificationToSend notificationToSend, String topic) {
Map<String, String> propertiesMap = new HashMap<>();
Optional.ofNullable(topic).ifPresent(value -> propertiesMap.put("topic", value));
Optional.ofNullable(notificationToSend.getId()).ifPresent(value -> propertiesMap.put("id", value));
Optional.ofNullable(notificationToSend.getInternalIstitutionID()).ifPresent(value -> propertiesMap.put("internalIstitutionID", value));
Optional.ofNullable(notificationToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void notificationEventMapTest() {
billing.setPublicService(false);
notificationToSend.setBilling(billing);

Map<String, String> properties = NotificationEventServiceDefault.notificationEventMap(notificationToSend);
Map<String, String> properties = NotificationEventServiceDefault.notificationEventMap(notificationToSend, "topic");
assertNotNull(properties);
assertEquals(properties.get("id"), "id");
assertEquals(properties.get("internalIstitutionID"), "internal");
Expand Down Expand Up @@ -261,7 +261,7 @@ void notificationEventMapRootParentTest() {
billing.setTaxCodeInvoicing("456");
notificationToSend.setBilling(billing);

Map<String, String> properties = NotificationEventServiceDefault.notificationEventMap(notificationToSend);
Map<String, String> properties = NotificationEventServiceDefault.notificationEventMap(notificationToSend, "topic");
assertNotNull(properties);
assertEquals(properties.get("id"), "id");
assertEquals(properties.get("internalIstitutionID"), "internal");
Expand Down
Loading