The success of Error Tracking
Two days ago error tracking was added to FastStats. Within the first 24 hours, I was able to identify and fix five issues in several of my plugins and two bugs within libraries.
None of these issues would have been caught without error tracking.
How does the error tracker work?
There are two modes for error tracking: context-aware and context-unaware.
The context-aware error tracker automatically tracks errors in the same class loader that would
otherwise be swallowed by the JVM and therefore stay virtually undetected.
The context-unaware error tracker does not automatically track any errors, the developer must manually track them.
The best practice is to use both methods, as they complement each other.
You attach a context-aware error tracker to your plugin and manually track errors where necessary.
Example Implementation
Implementing error tracking with our SDKs is as simple as adding a few lines of code:
// Create a context-aware error tracker
public static final ErrorTracker ERROR_TRACKER = ErrorTracker.contextAware();
private final Metrics fastStats = metricsFactory() // Platform-specific
.errorTracker(ERROR_TRACKER) // Attach the error tracker
.create(this); // Create the metrics instance
// Track an error manually
public void doSomethingWrong() {
try {
// Do something that might throw an error
riskyOperation();
} catch (Exception e) {
LOGGER.error("Operation failed", e); // Proper error handling
ERROR_TRACKER.trackError(e); // Track the error
}
}
// Automatically tracked error
public void doSomethingWrong() {
new Thread(() -> {
// This exception will automatically be tracked
throw new RuntimeException("Something went wrong!");
}).start();
}