Module: Familia::Instrumentation
- Defined in:
- lib/familia/instrumentation.rb
Overview
Provides instrumentation hooks for observability into Familia operations.
This module allows applications to register callbacks for various events in Familia's lifecycle, enabling audit trails, performance monitoring, and operational observability.
Class Method Summary collapse
-
.notify_command(cmd, duration, context = {}) ⇒ Object
private
Notify all registered command hooks.
-
.notify_error(error, context = {}) ⇒ Object
private
Notify all registered error hooks.
-
.notify_lifecycle(event, instance, context = {}) ⇒ Object
private
Notify all registered lifecycle hooks.
-
.notify_pipeline(command_count, duration, context = {}) ⇒ Object
private
Notify all registered pipeline hooks.
-
.on_command {|cmd, duration, context| ... } ⇒ Object
Register a callback for Redis command execution.
-
.on_error {|error, context| ... } ⇒ Object
Register a callback for error conditions.
-
.on_lifecycle {|event, instance, context| ... } ⇒ Object
Register a callback for Horreum lifecycle events.
-
.on_pipeline {|command_count, duration, context| ... } ⇒ Object
Register a callback for pipelined Redis operations.
Class Method Details
.notify_command(cmd, duration, context = {}) ⇒ 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.
Notify all registered command hooks.
117 118 119 120 121 122 123 |
# File 'lib/familia/instrumentation.rb', line 117 def notify_command(cmd, duration, context = {}) @hooks[:command].each do |hook| hook.call(cmd, duration, context) rescue => e Familia.error("Instrumentation hook failed", error: e., hook_type: :command) end end |
.notify_error(error, context = {}) ⇒ 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.
Notify all registered error hooks.
147 148 149 150 151 152 153 |
# File 'lib/familia/instrumentation.rb', line 147 def notify_error(error, context = {}) @hooks[:error].each do |hook| hook.call(error, context) rescue => e # Don't recurse on hook failures - just silently skip end end |
.notify_lifecycle(event, instance, context = {}) ⇒ 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.
Notify all registered lifecycle hooks.
137 138 139 140 141 142 143 |
# File 'lib/familia/instrumentation.rb', line 137 def notify_lifecycle(event, instance, context = {}) @hooks[:lifecycle].each do |hook| hook.call(event, instance, context) rescue => e Familia.error("Instrumentation hook failed", error: e., hook_type: :lifecycle) end end |
.notify_pipeline(command_count, duration, context = {}) ⇒ 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.
Notify all registered pipeline hooks.
127 128 129 130 131 132 133 |
# File 'lib/familia/instrumentation.rb', line 127 def notify_pipeline(command_count, duration, context = {}) @hooks[:pipeline].each do |hook| hook.call(command_count, duration, context) rescue => e Familia.error("Instrumentation hook failed", error: e., hook_type: :pipeline) end end |
.on_command {|cmd, duration, context| ... } ⇒ Object
Register a callback for Redis command execution.
55 56 57 |
# File 'lib/familia/instrumentation.rb', line 55 def on_command(&block) @hooks[:command] << block end |
.on_error {|error, context| ... } ⇒ Object
Register a callback for error conditions.
111 112 113 |
# File 'lib/familia/instrumentation.rb', line 111 def on_error(&block) @hooks[:error] << block end |
.on_lifecycle {|event, instance, context| ... } ⇒ Object
Register a callback for Horreum lifecycle events.
93 94 95 |
# File 'lib/familia/instrumentation.rb', line 93 def on_lifecycle(&block) @hooks[:lifecycle] << block end |
.on_pipeline {|command_count, duration, context| ... } ⇒ Object
Register a callback for pipelined Redis operations.
72 73 74 |
# File 'lib/familia/instrumentation.rb', line 72 def on_pipeline(&block) @hooks[:pipeline] << block end |