Class: Callstacking::Rails::Trace

Inherits:
Object
  • Object
show all
Includes:
Helpers::HeadsUpDisplayHelper
Defined in:
lib/callstacking/rails/trace.rb

Constant Summary collapse

TRACE_CALL_ENTRY =
'TraceCallEntry'
TRACE_CALL_RETURN =
'TraceCallReturn'
TRACE_MESSAGE =
'TraceMessage'
TRACE_EXCEPTION =
'TraceException'
ICON =
'💥'
MAX_TRACE_ENTRIES =
3000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::HeadsUpDisplayHelper

#hud, #inject_hud

Constructor Details

#initialize(spans) ⇒ Trace

Returns a new instance of Trace.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/callstacking/rails/trace.rb', line 26

def initialize(spans)

  @traces    = []
  @spans     = spans
  @settings  = Callstacking::Rails::Settings.new

  @lock     = Mutex.new
  @client   = Callstacking::Rails::Client::Trace.new(settings.url, settings.auth_token)

  init_uuids(nil, nil)
  init_callbacks(nil)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



15
16
17
# File 'lib/callstacking/rails/trace.rb', line 15

def client
  @client
end

#lockObject

Returns the value of attribute lock.



15
16
17
# File 'lib/callstacking/rails/trace.rb', line 15

def lock
  @lock
end

#settingsObject (readonly)

Returns the value of attribute settings.



16
17
18
# File 'lib/callstacking/rails/trace.rb', line 16

def settings
  @settings
end

#spansObject

Returns the value of attribute spans.



15
16
17
# File 'lib/callstacking/rails/trace.rb', line 15

def spans
  @spans
end

#tracesObject

Returns the value of attribute traces.



15
16
17
# File 'lib/callstacking/rails/trace.rb', line 15

def traces
  @traces
end

Class Method Details

.trace_log_clearObject



64
65
66
# File 'lib/callstacking/rails/trace.rb', line 64

def self.trace_log_clear
  trace_log.clear
end

Instance Method Details

#begin_trace(controller) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/callstacking/rails/trace.rb', line 39

def begin_trace(controller)
  @trace_id, @tuid = init_uuids(controller.request&.request_id || SecureRandom.uuid, TimeBasedUUID.generate)
  trace_log[@trace_id] = controller.request&.original_url
  
  init_callbacks(@tuid)

  start_request(@trace_id, @tuid,
                controller.action_name, controller.controller_name,
                controller.action_name, controller.request.format, ::Rails.root.to_s,
                controller.request&.original_url,
                controller.request.headers, controller.request.params, @traces)
end

#end_trace(controller, exception) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/callstacking/rails/trace.rb', line 52

def end_trace(controller, exception)
  return if @trace_id.nil? || @tuid.nil?
  
  complete_request(@trace_id, @tuid, exception,
                   controller.action_name, controller.controller_name,
                   controller.action_name, controller.request.format,
                   controller.request&.original_url,
                   @traces, MAX_TRACE_ENTRIES)

  inject_hud(@settings, controller.request, controller.response) if ::Rails.env.development? || ::Rails.env.test?
end