Class ErrorTracker

java.lang.Object
io.github.projectunified.faststats.core.Feature
io.github.projectunified.faststats.errortracker.ErrorTracker

public class ErrorTracker extends Feature
A feature that tracks uncaught and handled errors, anonymizes sensitive info, and submits report payloads.
  • Constructor Details

    • ErrorTracker

      public ErrorTracker()
      Creates a new error tracker feature that is context-unaware.
    • ErrorTracker

      public ErrorTracker(ClassLoader loader)
      Creates a new error tracker feature with the specified class loader.
      Parameters:
      loader - the class loader context
  • Method Details

    • contextAware

      public static ErrorTracker contextAware()
      Creates a context-aware error tracker feature.
      Returns:
      a new error tracker feature
    • contextUnaware

      public static ErrorTracker contextUnaware()
      Creates a context-unaware error tracker feature.
      Returns:
      a new error tracker feature
    • getDefaultProperties

      public Map<String,String> getDefaultProperties()
      Description copied from class: Feature
      Gets the default properties to assign to the configuration.
      Overrides:
      getDefaultProperties in class Feature
      Returns:
      the default properties
    • onStart

      public void onStart()
      Description copied from class: Feature
      Called when the Metrics coordinator is started. Subclasses can override this to initialize scheduling or start listeners.
      Overrides:
      onStart in class Feature
    • onShutdown

      public void onShutdown()
      Description copied from class: Feature
      Called when the Metrics coordinator is shutdown. Subclasses can override this to release resources or stop listeners.
      Overrides:
      onShutdown in class Feature
    • trackError

      public void trackError(String message)
      Tracks a handled error with the given message.
      Parameters:
      message - the error message
    • trackError

      public void trackError(Throwable error)
      Tracks a handled error.
      Parameters:
      error - the error
    • trackError

      public void trackError(String message, boolean handled)
      Tracks an error with the given message.
      Parameters:
      message - the error message
      handled - whether the error was handled
    • trackError

      public void trackError(Throwable error, boolean handled)
      Tracks an error.
      Parameters:
      error - the error
      handled - whether the error was handled
    • ignoreError

      public ErrorTracker ignoreError(Class<? extends Throwable> type)
      Adds an error type that will not be reported.
      Parameters:
      type - the error type
      Returns:
      this instance
    • ignoreError

      public ErrorTracker ignoreError(Pattern pattern)
      Adds a pattern that will be matched against error messages to ignore them.
      Parameters:
      pattern - the pattern
      Returns:
      this instance
    • ignoreError

      public ErrorTracker ignoreError(String pattern)
      Adds a pattern string that will be matched against error messages to ignore them.
      Parameters:
      pattern - the regex pattern
      Returns:
      this instance
    • ignoreError

      public ErrorTracker ignoreError(Class<? extends Throwable> type, Pattern pattern)
      Adds an error type and message pattern that will be ignored.
      Parameters:
      type - the error type
      pattern - the pattern
      Returns:
      this instance
    • ignoreError

      public ErrorTracker ignoreError(Class<? extends Throwable> type, String pattern)
      Adds an error type and message pattern string that will be ignored.
      Parameters:
      type - the error type
      pattern - the regex pattern
      Returns:
      this instance
    • anonymize

      public ErrorTracker anonymize(Pattern pattern, String replacement)
      Adds an anonymization pattern replacement rule.
      Parameters:
      pattern - the pattern to match
      replacement - the replacement string
      Returns:
      this instance
    • anonymize

      public ErrorTracker anonymize(String pattern, String replacement)
      Adds an anonymization pattern replacement rule.
      Parameters:
      pattern - the regex pattern to match
      replacement - the replacement string
      Returns:
      this instance
    • attachErrorContext

      public void attachErrorContext(ClassLoader classLoader) throws IllegalStateException
      Attaches uncaught error handling using the specified class loader.
      Parameters:
      classLoader - the class loader
      Throws:
      IllegalStateException - if already attached
    • detachErrorContext

      public void detachErrorContext()
      Detaches error context handling and restores the original handler.
    • isContextAttached

      public boolean isContextAttached()
      Gets whether an error context is currently attached.
      Returns:
      true if attached, false otherwise
    • getContextErrorHandler

      public Optional<BiConsumer<ClassLoader, Throwable>> getContextErrorHandler()
      Gets the error event handler.
      Returns:
      the handler
    • setContextErrorHandler

      public void setContextErrorHandler(BiConsumer<ClassLoader, Throwable> errorEvent)
      Sets the error event handler.
      Parameters:
      errorEvent - the handler