From bae241461c63df6d2a5759a9d2097b2fafb8c3eb Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Wed, 23 Nov 2022 23:06:37 +0530 Subject: [PATCH] chore: Add data points for debugging event log (#18404) --- .../services/ce/AnalyticsServiceCEImpl.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java index 21364177dc..2d8827ab59 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java @@ -17,6 +17,7 @@ import com.segment.analytics.messages.TrackMessage; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -24,6 +25,7 @@ import reactor.core.scheduler.Schedulers; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Slf4j public class AnalyticsServiceCEImpl implements AnalyticsServiceCE { @@ -127,6 +129,12 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE { // at java.base/java.util.ImmutableCollections$AbstractImmutableMap.put(ImmutableCollections.java) Map analyticsProperties = properties == null ? new HashMap<>() : new HashMap<>(properties); + // To debug the issue with userId empty error from segment + // TODO remove the code block once the issue is fixed + if (StringUtils.isEmpty(userId)) { + log.error(" UserId is null or empty. event Name is {}, analyticProperties is {}, hashUserId is {}", String.valueOf(userId), event, convertWithStream(properties), hashUserId); + } + // Hash usernames at all places for self-hosted instance if (userId != null && hashUserId @@ -260,4 +268,11 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE { public Mono sendDeleteEvent(T object) { return sendDeleteEvent(object, null); } + + public String convertWithStream(Map map) { + String mapAsString = map.keySet().stream() + .map(key -> key + "=" + map.get(key)) + .collect(Collectors.joining(", ", "{", "}")); + return mapAsString; + } }