|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
| 3 | +require_relative "../../core/component_access" |
| 4 | + |
3 | 5 | module Hooks |
4 | 6 | module Plugins |
5 | 7 | module Instruments |
6 | 8 | # Base class for all failbot instrument plugins |
7 | 9 | # |
8 | | - # All custom failbot implementations must inherit from this class and implement |
9 | | - # the required methods for error reporting. |
| 10 | + # This class provides the foundation for implementing custom error reporting |
| 11 | + # instruments. Subclasses should implement specific methods for their target |
| 12 | + # error reporting service (Sentry, Rollbar, Honeybadger, etc.). |
| 13 | + # |
| 14 | + # @abstract Subclass and implement service-specific error reporting methods |
| 15 | + # @example Implementing a custom failbot instrument |
| 16 | + # class MySentryFailbot < Hooks::Plugins::Instruments::FailbotBase |
| 17 | + # def report(error_or_message, context = {}) |
| 18 | + # case error_or_message |
| 19 | + # when Exception |
| 20 | + # Sentry.capture_exception(error_or_message, extra: context) |
| 21 | + # else |
| 22 | + # Sentry.capture_message(error_or_message.to_s, extra: context) |
| 23 | + # end |
| 24 | + # log.debug("Reported error to Sentry") |
| 25 | + # end |
| 26 | + # end |
| 27 | + # |
| 28 | + # @see Hooks::Plugins::Instruments::Failbot |
10 | 29 | class FailbotBase |
11 | | - # Short logger accessor for all subclasses |
12 | | - # @return [Hooks::Log] Logger instance |
| 30 | + include Hooks::Core::ComponentAccess |
| 31 | + |
| 32 | + # Report an error or message to the error tracking service |
| 33 | + # |
| 34 | + # This is a no-op implementation that subclasses should override |
| 35 | + # to provide actual error reporting functionality. |
| 36 | + # |
| 37 | + # @param error_or_message [Exception, String] The error to report or message string |
| 38 | + # @param context [Hash] Additional context information about the error |
| 39 | + # @return [void] |
| 40 | + # @note Subclasses should implement this method for their specific service |
| 41 | + # @example Override in subclass |
| 42 | + # def report(error_or_message, context = {}) |
| 43 | + # if error_or_message.is_a?(Exception) |
| 44 | + # ErrorService.report_exception(error_or_message, context) |
| 45 | + # else |
| 46 | + # ErrorService.report_message(error_or_message, context) |
| 47 | + # end |
| 48 | + # end |
| 49 | + def report(error_or_message, context = {}) |
| 50 | + # No-op implementation for base class |
| 51 | + end |
| 52 | + |
| 53 | + # Report a warning-level message |
13 | 54 | # |
14 | | - # Provides a convenient way for instruments to log messages without needing |
15 | | - # to reference the full Hooks::Log namespace. |
| 55 | + # This is a no-op implementation that subclasses should override |
| 56 | + # to provide actual warning reporting functionality. |
16 | 57 | # |
17 | | - # @example Logging debug info in an inherited class |
18 | | - # log.debug("Sending error to external service") |
19 | | - def log |
20 | | - Hooks::Log.instance |
| 58 | + # @param message [String] Warning message to report |
| 59 | + # @param context [Hash] Additional context information |
| 60 | + # @return [void] |
| 61 | + # @note Subclasses should implement this method for their specific service |
| 62 | + # @example Override in subclass |
| 63 | + # def warn(message, context = {}) |
| 64 | + # ErrorService.report_warning(message, context) |
| 65 | + # end |
| 66 | + def warn(message, context = {}) |
| 67 | + # No-op implementation for base class |
21 | 68 | end |
22 | 69 | end |
23 | 70 | end |
|
0 commit comments