Module: Anyway::Tracing
- Included in:
- Env, Loaders::Base
- Defined in:
- lib/anyway/tracing.rb
Overview
Provides method to trace values association
Defined Under Namespace
Classes: Trace
Class Method Summary collapse
- .capture ⇒ Object
- .current_trace ⇒ Object (also: tracing?)
- .current_trace_source ⇒ Object
- .source_stack ⇒ Object
- .trace!(type, *path, **opts) ⇒ Object
- .trace_stack ⇒ Object
- .with_trace_source(src) ⇒ Object
Class Method Details
.capture ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/anyway/tracing.rb', line 131 def capture unless Settings.tracing_enabled yield return end trace = Trace.new trace_stack.push trace yield trace_stack.last ensure trace_stack.pop end |
.current_trace ⇒ Object Also known as: tracing?
149 150 151 |
# File 'lib/anyway/tracing.rb', line 149 def current_trace trace_stack.last end |
.current_trace_source ⇒ Object
159 160 161 |
# File 'lib/anyway/tracing.rb', line 159 def current_trace_source source_stack.last || accessor_source(caller_locations(2, 1).first) end |
.source_stack ⇒ Object
155 156 157 |
# File 'lib/anyway/tracing.rb', line 155 def source_stack (Thread.current[:__anyway__trace_source_stack__] ||= []) end |
.trace!(type, *path, **opts) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/anyway/tracing.rb', line 179 def trace!(type, *path, **opts) return yield unless Tracing.tracing? source = {type: type}.merge(opts) val = yield if val.is_a?(Hash) Tracing.current_trace.merge_values(val, **source) else Tracing.current_trace.record_value(val, *path, **source) end val end |
.trace_stack ⇒ Object
145 146 147 |
# File 'lib/anyway/tracing.rb', line 145 def trace_stack (Thread.current[:__anyway__trace_stack__] ||= []) end |
.with_trace_source(src) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/anyway/tracing.rb', line 163 def with_trace_source(src) source_stack << src yield ensure source_stack.pop end |