Module: Checkend
- Defined in:
- lib/checkend.rb,
lib/checkend/client.rb,
lib/checkend/notice.rb,
lib/checkend/worker.rb,
lib/checkend/testing.rb,
lib/checkend/version.rb,
lib/checkend/configuration.rb,
lib/checkend/notice_builder.rb,
lib/checkend/integrations/rack.rb,
lib/checkend/integrations/rails.rb,
lib/checkend/integrations/rails.rb,
lib/checkend/integrations/sidekiq.rb,
lib/checkend/filters/ignore_filter.rb,
lib/checkend/filters/sanitize_filter.rb,
lib/checkend/integrations/active_job.rb
Overview
Checkend is the main module for the Checkend Ruby SDK.
Use Checkend.configure to set up the SDK, then Checkend.notify to report errors.
Defined Under Namespace
Modules: Filters, Integrations, Testing Classes: Client, Configuration, Notice, NoticeBuilder, Worker
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
-
.clear! ⇒ Object
Clear all thread-local context.
-
.configuration ⇒ Configuration
Get the current configuration.
-
.configure {|Configuration| ... } ⇒ Configuration
Configure the Checkend SDK.
-
.context ⇒ Hash
Get the current thread-local context.
-
.current_user ⇒ Hash?
Get the current user.
-
.flush(timeout: nil) ⇒ Object
Flush pending notices, blocking until sent.
-
.logger ⇒ Logger
Get the logger.
-
.notify(exception, context: {}, request: nil, user: nil, fingerprint: nil, tags: []) ⇒ Hash?
Report an exception to Checkend.
-
.notify_sync(exception, **options) ⇒ Hash?
Report an exception synchronously (blocking).
-
.reset! ⇒ void
Reset all SDK state (useful for testing).
-
.set_context(hash) ⇒ Object
Set context data for the current thread.
-
.set_user(user_hash) ⇒ Object
Set user information for the current thread.
-
.start! ⇒ Object
Start the SDK (initialize client, worker, etc.).
-
.stop!(timeout: nil) ⇒ Object
Stop the SDK and clean up resources.
Class Method Details
.clear! ⇒ Object
Clear all thread-local context
154 155 156 157 |
# File 'lib/checkend.rb', line 154 def clear! Thread.current[:checkend_context] = nil Thread.current[:checkend_user] = nil end |
.configuration ⇒ Configuration
Get the current configuration
33 34 35 |
# File 'lib/checkend.rb', line 33 def configuration @configuration ||= Configuration.new end |
.configure {|Configuration| ... } ⇒ Configuration
Configure the Checkend SDK
41 42 43 44 45 |
# File 'lib/checkend.rb', line 41 def configure yield(configuration) if block_given? start! if configuration.valid? configuration end |
.context ⇒ Hash
Get the current thread-local context
127 128 129 |
# File 'lib/checkend.rb', line 127 def context Thread.current[:checkend_context] ||= {} end |
.current_user ⇒ Hash?
Get the current user
149 150 151 |
# File 'lib/checkend.rb', line 149 def current_user Thread.current[:checkend_user] end |
.flush(timeout: nil) ⇒ Object
Flush pending notices, blocking until sent
74 75 76 |
# File 'lib/checkend.rb', line 74 def flush(timeout: nil) @worker&.flush(timeout: timeout) end |
.logger ⇒ Logger
Get the logger
177 178 179 |
# File 'lib/checkend.rb', line 177 def logger configuration.resolved_logger end |
.notify(exception, context: {}, request: nil, user: nil, fingerprint: nil, tags: []) ⇒ Hash?
Report an exception to Checkend
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/checkend.rb', line 89 def notify(exception, context: {}, request: nil, user: nil, fingerprint: nil, tags: []) return nil unless should_notify? return nil if configuration.ignore_exception?(exception) notice = NoticeBuilder.build( exception: exception, context: context, request: request, user: user, fingerprint: fingerprint, tags: ) # Run before_notify callbacks return nil unless before_notify_callbacks_allow?(notice) send_notice(notice) end |
.notify_sync(exception, **options) ⇒ Hash?
Report an exception synchronously (blocking)
Useful for CLI tools, tests, or when you need confirmation of delivery.
115 116 117 118 119 120 |
# File 'lib/checkend.rb', line 115 def notify_sync(exception, **) return nil unless should_notify? notice = NoticeBuilder.build(exception: exception, **) client.send_notice(notice) end |
.reset! ⇒ void
This method returns an undefined value.
Reset all SDK state (useful for testing)
162 163 164 165 166 167 168 169 170 |
# File 'lib/checkend.rb', line 162 def reset! stop!(timeout: 0) if @started @configuration = nil @client = nil @worker = nil @started = false @at_exit_installed = nil clear! end |
.set_context(hash) ⇒ Object
Set context data for the current thread
134 135 136 137 |
# File 'lib/checkend.rb', line 134 def set_context(hash) Thread.current[:checkend_context] ||= {} Thread.current[:checkend_context].merge!(hash) end |
.set_user(user_hash) ⇒ Object
Set user information for the current thread
142 143 144 |
# File 'lib/checkend.rb', line 142 def set_user(user_hash) Thread.current[:checkend_user] = user_hash end |
.start! ⇒ Object
Start the SDK (initialize client, worker, etc.)
Called automatically after configure if configuration is valid.
50 51 52 53 54 55 56 57 58 |
# File 'lib/checkend.rb', line 50 def start! return if @started @started = true @client = Client.new(configuration) @worker = Worker.new(configuration) if configuration.async install_at_exit_hook log_info("Started (environment: #{configuration.environment}, async: #{configuration.async})") end |
.stop!(timeout: nil) ⇒ Object
Stop the SDK and clean up resources
63 64 65 66 67 68 69 |
# File 'lib/checkend.rb', line 63 def stop!(timeout: nil) @worker&.shutdown(timeout: timeout) @worker = nil @started = false @client = nil log_info('Stopped') end |