Module: StandardHealth::EventEmitter Private

Defined in:
lib/standard_health/event_emitter.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal helper that emits StandardHealth events through whichever event reporter is live in the host process.

  • On Rails 8.1+, Rails.event.notify(name, **payload) is the canonical bus.
  • On older Rails (or any host without the structured reporter), we fall back to ActiveSupport::Notifications.instrument(name, payload).

Detection is performed at call time — the gem is required before Rails has finished booting, so we cannot cache the decision at load time.

This mirrors StandardCircuit::EventEmitter deliberately: one idiom for observability across the standard_* gems.

Class Method Summary collapse

Class Method Details

.emit(event_name, payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Emit a single event. Both backends are best-effort: any exception raised by a subscriber is swallowed so health observability never takes down the health path itself. See .claude/rules/never-raise.md — instrumentation must not become a new way for /ready to 500.



25
26
27
28
29
30
31
32
33
# File 'lib/standard_health/event_emitter.rb', line 25

def emit(event_name, payload)
  if rails_event_available?
    ::Rails.event.notify(event_name, **payload)
  else
    ::ActiveSupport::Notifications.instrument(event_name, payload)
  end
rescue => e
  warn "[StandardHealth] event emit for #{event_name.inspect} failed: #{e.class}: #{e.message}"
end

.rails_event_available?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/standard_health/event_emitter.rb', line 35

def rails_event_available?
  defined?(::Rails) &&
    ::Rails.respond_to?(:event) &&
    ::Rails.event.respond_to?(:notify)
end