Module: Bitfab::ReplayContext
- Defined in:
- lib/bitfab/replay.rb
Overview
Thread-local replay context management.
Class Method Summary collapse
- .current ⇒ Object
-
.with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, trace_id: nil, mock_tree: nil, mock_strategy: nil, pending_persistence: nil) ⇒ Object
Execute a block with replay context set on the current thread.
Class Method Details
.current ⇒ Object
19 20 21 |
# File 'lib/bitfab/replay.rb', line 19 def current Thread.current[REPLAY_CONTEXT_KEY] end |
.with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, trace_id: nil, mock_tree: nil, mock_strategy: nil, pending_persistence: nil) ⇒ Object
Execute a block with replay context set on the current thread. The context is automatically cleared when the block completes.
pending_persistence, when given, collects the root span’s persistence threads (span uploads + trace completion) so the replay runner can join them before complete_replay builds the trace-ID mapping.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bitfab/replay.rb', line 29 def with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, trace_id: nil, mock_tree: nil, mock_strategy: nil, pending_persistence: nil) previous = Thread.current[REPLAY_CONTEXT_KEY] ctx = { test_run_id:, input_source_span_id:, input_source_trace_id:, trace_id: } ctx[:pending_persistence] = pending_persistence if pending_persistence if mock_tree ctx[:mock_tree] = mock_tree ctx[:mock_strategy] = mock_strategy || "none" ctx[:call_counters] = {} end Thread.current[REPLAY_CONTEXT_KEY] = ctx yield ensure Thread.current[REPLAY_CONTEXT_KEY] = previous end |