Module: MetrixWire::Context
- Defined in:
- lib/metrixwire/context.rb
Overview
Thread/fiber-local "current trace" holder. Every entry point (Rack middleware, ActiveSupport subscribers, DB/HTTP patches) reads the active trace from here so spans attach to the right request. Fiber-local storage (Thread#[]) keeps concurrent requests isolated on threaded servers.
Constant Summary collapse
- KEY =
:__metrixwire_current_trace__
Class Method Summary collapse
- .clear ⇒ Object
- .current ⇒ Object
- .current=(trace) ⇒ Object
-
.with(trace) ⇒ Object
Run a block with
traceas the active trace, restoring the previous one afterwards.
Class Method Details
.clear ⇒ Object
31 32 33 |
# File 'lib/metrixwire/context.rb', line 31 def clear Thread.current[KEY] = nil end |
.current ⇒ Object
13 14 15 |
# File 'lib/metrixwire/context.rb', line 13 def current Thread.current[KEY] end |
.current=(trace) ⇒ Object
17 18 19 |
# File 'lib/metrixwire/context.rb', line 17 def current=(trace) Thread.current[KEY] = trace end |
.with(trace) ⇒ Object
Run a block with trace as the active trace, restoring the previous one
afterwards. Restores even if the block raises.
23 24 25 26 27 28 29 |
# File 'lib/metrixwire/context.rb', line 23 def with(trace) prev = Thread.current[KEY] Thread.current[KEY] = trace yield ensure Thread.current[KEY] = prev end |