Skip to content

Commit

Permalink
Improve telemetry (#3218)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez authored and lenhard committed Sep 14, 2017
1 parent d941731 commit c282367
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/org/jabref/FallbackExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package org.jabref;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Catch and log any unhandled exceptions.
*/
public class FallbackExceptionHandler implements Thread.UncaughtExceptionHandler {

private static final Marker UncaughtException_MARKER = MarkerManager.getMarker("UncaughtException");
private static final Log LOGGER = LogFactory.getLog(FallbackExceptionHandler.class);

public static void installExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler(new FallbackExceptionHandler());
}

@Override
public void uncaughtException(Thread thread, Throwable exception) {
Logger logger = LogManager.getLogger(FallbackExceptionHandler.class);
logger.error(UncaughtException_MARKER, "Uncaught exception Occurred in " + thread, exception);
LOGGER.error("Uncaught exception occurred in " + thread, exception);
}
}
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/actions/NewEntryAction.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.jabref.gui.actions;

import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Action;
import javax.swing.KeyStroke;

import org.jabref.Globals;
import org.jabref.gui.EntryTypeDialog;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefFrame;
Expand Down Expand Up @@ -58,6 +61,8 @@ public void actionPerformed(ActionEvent e) {
return;
}
thisType = tp.getName();

trackNewEntry(tp);
}

if (jabRefFrame.getBasePanelCount() > 0) {
Expand All @@ -68,4 +73,12 @@ public void actionPerformed(ActionEvent e) {
LOGGER.info("Action 'New entry' must be disabled when no database is open.");
}
}

private void trackNewEntry(EntryType type) {
Map<String, String> properties = new HashMap<>();
properties.put("EntryType", type.getName());
Map<String, Double> measurements = new HashMap<>();

Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("NewEntry", properties, measurements));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void append(LogEvent rawEvent) {
Telemetry telemetry;
if (event.isException()) {
ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(event.getException());
exceptionTelemetry.getProperties().put("Message", rawEvent.getMessage().getFormattedMessage());
exceptionTelemetry.setSeverityLevel(event.getNormalizedSeverityLevel());
telemetry = exceptionTelemetry;
} else {
Expand Down

0 comments on commit c282367

Please sign in to comment.