From 161815be569aeb94cbe7e966496af2d09934936a Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Wed, 17 Apr 2024 15:38:33 -0400 Subject: [PATCH] Report only one instance of a logged error through telemetry. Signed-off-by: Roland Grunberg --- .../ls/core/internal/handlers/LogHandler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/LogHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/LogHandler.java index 52382f81b7..b6b79a5196 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/LogHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/LogHandler.java @@ -20,7 +20,9 @@ import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Predicate; import org.eclipse.core.resources.IWorkspaceRoot; @@ -61,6 +63,7 @@ public class LogHandler { private String firstRecordedEntryDateString; private List statusCache = new ArrayList<>(); + private Set knownErrors = new HashSet<>(); /** * Equivalent to LogHandler(defaultLogFilter). @@ -106,6 +109,7 @@ public void setClientConnection(JavaClientConnection clientConnection) { for (IStatus event : statusCache) { processLogMessage(event); } + statusCache.clear(); for (LogEntry e : entries) { processLogMessage(e); @@ -139,7 +143,11 @@ private void processLogMessage(LogEntry entry) { if (entry.getStack() != null) { properties.addProperty("exception", message); } - connection.telemetryEvent(new TelemetryEvent(JAVA_ERROR_LOG, properties)); + int hashCode = properties.hashCode(); + if (!knownErrors.contains(hashCode)) { + knownErrors.add(hashCode); + connection.telemetryEvent(new TelemetryEvent(JAVA_ERROR_LOG, properties)); + } } } private void processLogMessage(IStatus status) { @@ -165,7 +173,11 @@ private void processLogMessage(IStatus status) { if (status.getException() != null) { properties.addProperty("exception", message); } - connection.telemetryEvent(new TelemetryEvent(JAVA_ERROR_LOG, properties)); + int hashCode = properties.hashCode(); + if (!knownErrors.contains(hashCode)) { + knownErrors.add(hashCode); + connection.telemetryEvent(new TelemetryEvent(JAVA_ERROR_LOG, properties)); + } } }