Module: LogBrew::Telemetry
- Defined in:
- lib/logbrew/telemetry.rb
Overview
Fiber/thread-local shared context for request, job, and operation boundaries.
Class Method Summary collapse
- .activate_context(context) ⇒ Object
- .close_scope(activation_id) ⇒ Object
- .current_context ⇒ Object
- .with_context(context) ⇒ Object
Class Method Details
.activate_context(context) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/logbrew/telemetry.rb', line 31 def activate_context(context) unless context.is_a?(TelemetryContext) raise TelemetryContextValue.invalid("context must be a LogBrew::TelemetryContext") end merged = TelemetryContext.merge(current_context, context) activation_id = Object.new stack << { id: activation_id, context: merged } TelemetryScope.new(activation_id) end |
.close_scope(activation_id) ⇒ Object
49 50 51 52 53 |
# File 'lib/logbrew/telemetry.rb', line 49 def close_scope(activation_id) entries = stack index = entries.rindex { |entry| entry[:id].equal?(activation_id) } entries.delete_at(index) unless index.nil? end |
.current_context ⇒ Object
26 27 28 29 |
# File 'lib/logbrew/telemetry.rb', line 26 def current_context entry = stack.last entry && entry[:context] end |
.with_context(context) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/logbrew/telemetry.rb', line 42 def with_context(context) scope = activate_context(context) yield context ensure scope.close if scope end |