Skip to content

Commit

Permalink
Report only one instance of a logged error through telemetry.
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Jun 13, 2024
1 parent 02b046f commit 161815b
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class LogHandler {
private String firstRecordedEntryDateString;

private List<IStatus> statusCache = new ArrayList<>();
private Set<Integer> knownErrors = new HashSet<>();

/**
* Equivalent to <code>LogHandler(defaultLogFilter)</code>.
Expand Down Expand Up @@ -106,6 +109,7 @@ public void setClientConnection(JavaClientConnection clientConnection) {
for (IStatus event : statusCache) {
processLogMessage(event);
}
statusCache.clear();

for (LogEntry e : entries) {
processLogMessage(e);
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}
}
}

Expand Down

0 comments on commit 161815b

Please sign in to comment.