import pt.bitreport.errors.ErrorReporter; import java.util.Map; /** * Basic usage example for the BitReport Java error reporter. * * Compile and run: * javac -cp path/to/bitreport-errors-1.0.0.jar BasicUsage.java * ERROR_REPORTING_TOKEN=your_token java -cp .:path/to/bitreport-errors-1.0.0.jar BasicUsage */ public class BasicUsage { public static void main(String[] args) { ErrorReporter.init(ErrorReporter.Config.builder() .token(System.getenv("ERROR_REPORTING_TOKEN")) .projectName("My Java App") .projectSlug("my-java-app") .build()); // Always flush before the JVM exits Runtime.getRuntime().addShutdownHook(new Thread(ErrorReporter::flush)); // Report a plain message ErrorReporter.reportMessage("Application started", "info", null); // Report a warning with context ErrorReporter.reportMessage("Cache miss", "warning", Map.of("cache_key", "user:42")); // Report a caught exception try { int result = Integer.parseInt("not-a-number"); } catch (NumberFormatException e) { ErrorReporter.reportError(e, Map.of("input", "not-a-number")); } // Flush synchronously so the example does not exit with pending events ErrorReporter.flush(); System.out.println("Events sent. Check your errors.bitreport.pt dashboard."); } }