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

Class Method Details

.captureObject



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_traceObject Also known as: tracing?



149
# File 'lib/anyway/tracing.rb', line 149

def current_trace() = trace_stack.last

.current_trace_sourceObject



157
158
159
# File 'lib/anyway/tracing.rb', line 157

def current_trace_source
  source_stack.last || accessor_source(caller_locations(2, 1).first)
end

.source_stackObject



153
154
155
# File 'lib/anyway/tracing.rb', line 153

def source_stack
  (Thread.current[:__anyway__trace_source_stack__] ||= [])
end

.trace!(type, *path, **opts) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/anyway/tracing.rb', line 177

def trace!(type, *path, **opts)
  return yield unless Tracing.tracing?
  val = yield
  if val.is_a?(Hash)
    Tracing.current_trace.merge_values(val, type:, **opts)
  else
    Tracing.current_trace.record_value(val, *path, type:, **opts)
  end
  val
end

.trace_stackObject



145
146
147
# File 'lib/anyway/tracing.rb', line 145

def trace_stack
  (Thread.current[:__anyway__trace_stack__] ||= [])
end

.with_trace_source(src) ⇒ Object



161
162
163
164
165
166
# File 'lib/anyway/tracing.rb', line 161

def with_trace_source(src)
  source_stack << src
  yield
ensure
  source_stack.pop
end