Skip to content

Commit

Permalink
feat: [LT-1361] Additional log for messages that will be sent to mpar… (
Browse files Browse the repository at this point in the history
#19)

* feat: [LT-1361] Additional log for messages that will be sent to mparticle.
This is super useful for debugging so I want to make sure we can turn that on.

* refactor: [LT-1361] Move logging to a separate method.
  • Loading branch information
bge-kernel-panic authored Dec 10, 2024
1 parent e0ad6e3 commit 199977c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/java/com/sailthru/sqs/MParticleClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sailthru.sqs;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mparticle.client.EventsApi;
import com.mparticle.model.Batch;
import com.sailthru.sqs.exception.NoRetryException;
Expand All @@ -16,7 +18,7 @@
import java.time.Instant;
import java.util.Optional;

import static java.lang.String.format;
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
import static java.util.function.Predicate.not;

public class MParticleClient {
Expand All @@ -28,6 +30,7 @@ public class MParticleClient {
static final String DEFAULT_BASE_URL = "https://inbound.mparticle.com/s2s/v2/";

private final ApiFactory apiFactory;
private static final ObjectMapper DEBUG_SERIALIZER = new ObjectMapper().setSerializationInclusion(NON_EMPTY);

public MParticleClient(ApiFactory apiFactory) {
this.apiFactory = apiFactory;
Expand All @@ -40,7 +43,7 @@ public void submit(final MParticleOutgoingMessage message) throws RetryLaterExce

final EventsApi eventsApi = getEventsApi(message);

LOGGER.debug("Attempting to send batch: {} for message: {}", batch, message);
logReceivedAndTranslatedMessage(message, batch);

final Call<Void> singleResult = eventsApi.uploadEvents(batch);

Expand Down Expand Up @@ -119,4 +122,22 @@ private String normalizeUrl(String url) {
}
return url;
}

private static void logReceivedAndTranslatedMessage(MParticleOutgoingMessage message, Batch batch) {
if (LOGGER.isDebugEnabled()) {
String batchJson, messageJson;
try {
batchJson = DEBUG_SERIALIZER.writeValueAsString(batch);
} catch (JsonProcessingException e) {
batchJson = "(unserializable)";
}
try {
messageJson = DEBUG_SERIALIZER.writeValueAsString(message);
} catch (JsonProcessingException e) {
messageJson = "(unserializable)";
}

LOGGER.debug("Attempting to send batch: {} for message: {}", batchJson, messageJson);
}
}
}

0 comments on commit 199977c

Please sign in to comment.