Class: Lyra::Correlation
- Inherits:
-
Object
- Object
- Lyra::Correlation
- Defined in:
- lib/lyra/correlation.rb
Overview
Correlation system for grouping related operations and events correlation_id: Groups all events from the same user action (e.g., all events from one HTTP request)
Class Method Summary collapse
-
.current_id ⇒ Object
Current correlation ID (thread-safe).
-
.generate_id ⇒ Object
Generate a unique correlation ID for a group of operations.
-
.with_id(correlation_id = nil) ⇒ Object
Set correlation ID for current context.
Class Method Details
.current_id ⇒ Object
Current correlation ID (thread-safe)
12 13 14 |
# File 'lib/lyra/correlation.rb', line 12 def current_id Thread.current[:lyra_correlation_id] end |
.generate_id ⇒ Object
Generate a unique correlation ID for a group of operations
7 8 9 |
# File 'lib/lyra/correlation.rb', line 7 def generate_id "corr_#{Time.now.to_i}_#{SecureRandom.hex(8)}" end |
.with_id(correlation_id = nil) ⇒ Object
Set correlation ID for current context
17 18 19 20 21 22 23 24 25 |
# File 'lib/lyra/correlation.rb', line 17 def with_id(correlation_id = nil) correlation_id ||= generate_id previous_id = Thread.current[:lyra_correlation_id] Thread.current[:lyra_correlation_id] = correlation_id yield correlation_id if block_given? ensure Thread.current[:lyra_correlation_id] = previous_id end |