callstacking-rails 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11d37da94e52c249d1b591d2a0c5dfef5f55c133e5336bea6b4db341a839dffa
4
- data.tar.gz: fd8b20d2b04e23b3833da9ac7fd122e6b6fff36a6b60313fda462651c5876d4a
3
+ metadata.gz: c8f0e31ee61913c798aa308ed0d92c76b8755cc0f6a884c0530792a23a0632e8
4
+ data.tar.gz: 04f3fe70825ec3f94c4d3b2d6c700cb55f457444376ffb066884a80ad4a5fb37
5
5
  SHA512:
6
- metadata.gz: 3f8908e29235fdd5a35fb176b0569042f9fc8c395d4cfebaaa87e62c1068a95500d5e6e67490168788ba58787ba811ecc3c623a831620f0df5a9642b5c4dd6b6
7
- data.tar.gz: 28d4e721755cddcaa11535defc51523c64323aca6162831cc8e436ea3ec032a4aebdfc84884464f78ec48a93eaa0228a09f82b352e84bbfdeec2b23c4e5e1c45
6
+ metadata.gz: 4b90cd3642f0b451347aae60efe9174400c66c155d2d5f19b719b9a21c73f730c5a0a3748aa2d0d736c9f001d2e9027a070429a7653bb6e4aa112328fc7ee120
7
+ data.tar.gz: a42354436d3edbc0d8b02878731435f9b3b2f23b7281f011cae9b8fff8220750d4081fc75572595b132560c75d87de1f150df8a9fb8a4c8ace4f591f40f1af3b
@@ -73,7 +73,7 @@ module Callstacking
73
73
  true
74
74
  end
75
75
 
76
- def self.stop_tracing(controller)
76
+ def self.stop_tracing(controller, exception)
77
77
  Logger.log("Callstacking::Rails::Engine.stop_tracing")
78
78
 
79
79
  settings.disable!
@@ -86,8 +86,12 @@ module Callstacking
86
86
  end
87
87
  end
88
88
 
89
- trace&.end_trace(controller)
90
-
89
+ trace&.end_trace(controller, exception)
90
+
91
+ lock.synchronize do
92
+ spans[Thread.current.object_id]&.reset
93
+ end
94
+
91
95
  true
92
96
  end
93
97
  end
@@ -4,13 +4,37 @@ module Callstacking
4
4
  module InstrumentHelper
5
5
  extend ActiveSupport::Concern
6
6
  def callstacking_setup
7
+ exception = nil
8
+ @last_callstacking_sample = TIme.utc.now
7
9
  Callstacking::Rails::Engine.start_tracing(self)
8
10
 
9
11
  yield
12
+ rescue Exception => e
13
+ @last_callstacking_exception = Time.utc.now
14
+ exception = e
15
+ raise e
10
16
  ensure
11
- Callstacking::Rails::Engine.stop_tracing(self)
17
+ Callstacking::Rails::Engine.stop_tracing(self, exception)
12
18
  end
13
19
  end
20
+
21
+ def callstcking_sample_trace?
22
+ if @last_callstacking_exception.present? && @last_callstacking_exception < 1.minute.ago
23
+ @last_callstacking_exception = nil
24
+ return true
25
+ end
26
+
27
+ false
28
+ end
29
+
30
+ def callstacking_followup_exception_trace?
31
+ if @last_callstacking_sample.present? && @last_callstacking_sample < 1.hour.ago
32
+ @last_callstacking_exception = nil
33
+ return true
34
+ end
35
+
36
+ false
37
+ end
14
38
  end
15
39
  end
16
40
  end
@@ -39,8 +39,8 @@ module Callstacking
39
39
 
40
40
  method_name = __method__
41
41
 
42
- path = method(__method__).super_method.source_location.first
43
- line_no = method(__method__).super_method.source_location.last
42
+ path = method(__method__).super_method.source_location&.first || ''
43
+ line_no = method(__method__).super_method.source_location&.last || ''
44
44
 
45
45
  p, l = caller.find { |c| c.to_s =~ /#{::Rails.root.to_s}/}&.split(':')
46
46
 
@@ -64,8 +64,8 @@ module Callstacking
64
64
 
65
65
  method_name = __method__
66
66
 
67
- path = method(__method__).super_method.source_location.first
68
- line_no = method(__method__).super_method.source_location.last
67
+ path = method(__method__).super_method.source_location&.first || ''
68
+ line_no = method(__method__).super_method.source_location&.last || ''
69
69
 
70
70
  p, l = caller.find { |c| c.to_s =~ /#{::Rails.root.to_s}/}&.split(':')
71
71
 
@@ -5,9 +5,7 @@ module Callstacking
5
5
  attr_accessor :call_entry_callback, :call_return_callback
6
6
 
7
7
  def initialize
8
- @nesting_level = -1
9
- @order_num = -1
10
- @previous_entry = nil
8
+ reset
11
9
  end
12
10
 
13
11
  def increment_order_num
@@ -40,6 +38,12 @@ module Callstacking
40
38
  @call_return_callback = block
41
39
  end
42
40
 
41
+ def reset
42
+ @nesting_level = -1
43
+ @order_num = -1
44
+ @previous_entry = nil
45
+ end
46
+
43
47
  private
44
48
  def previous_event(klass, method_name)
45
49
  "#{klass}:#{method_name}"
@@ -5,6 +5,11 @@ require "callstacking/rails/helpers/heads_up_display_helper"
5
5
  module Callstacking
6
6
  module Rails
7
7
  class Trace
8
+ TRACE_CALL_ENTRY = 'TraceCallEntry'
9
+ TRACE_CALL_RETURN = 'TraceCallReturn'
10
+ TRACE_MESSAGE = 'TraceMessage'
11
+ TRACE_EXCEPTION = 'TraceException'
12
+
8
13
  include Callstacking::Rails::Helpers::HeadsUpDisplayHelper
9
14
 
10
15
  attr_accessor :spans, :client, :lock, :traces
@@ -44,16 +49,16 @@ module Callstacking
44
49
  controller.request.headers, controller.request.params, @traces)
45
50
  end
46
51
 
47
- def end_trace(controller)
52
+ def end_trace(controller, exception)
48
53
  return if @trace_id.nil? || @tuid.nil?
49
54
 
50
- complete_request(@trace_id, @tuid,
55
+ complete_request(@trace_id, @tuid, exception,
51
56
  controller.action_name, controller.controller_name,
52
57
  controller.action_name, controller.request.format,
53
58
  controller.request&.original_url,
54
59
  @traces, MAX_TRACE_ENTRIES)
55
60
 
56
- inject_hud(@settings, controller.request, controller.response)
61
+ inject_hud(@settings, controller.request, controller.response) if ::Rails.env.development? || ::Rails.env.test?
57
62
  end
58
63
 
59
64
  def self.trace_log_clear
@@ -87,10 +92,15 @@ module Callstacking
87
92
  "Started request: #{method} #{controller}##{action} as #{format}"
88
93
  end
89
94
 
95
+ def exception_message(exception, method, controller, action, format)
96
+ "#{exception.class} #{exception.message}<br/><br/>" \
97
+ "#{exception.backtrace[0]}".html_safe
98
+ end
99
+
90
100
  def create_call_return(tuid, coupled_callee, nesting_level, order_num, klass, method_name, path, line_no, return_val, traces)
91
101
  lock.synchronize do
92
102
  traces << { tuid: tuid,
93
- type: 'TraceCallReturn',
103
+ type: TRACE_CALL_RETURN,
94
104
  order_num: order_num,
95
105
  nesting_level: nesting_level,
96
106
  local_variables: {},
@@ -109,7 +119,7 @@ module Callstacking
109
119
  def create_call_entry(tuid, nesting_level, order_num, klass, method_name, arguments, path, line_no, traces)
110
120
  lock.synchronize do
111
121
  traces << { tuid: tuid,
112
- type: 'TraceCallEntry',
122
+ type: TRACE_CALL_ENTRY,
113
123
  order_num: order_num,
114
124
  nesting_level: nesting_level,
115
125
  args: arguments,
@@ -125,10 +135,10 @@ module Callstacking
125
135
  end
126
136
  end
127
137
 
128
- def create_message(tuid, message, order_num, traces)
138
+ def create_message(tuid, message, order_num, traces, type = TRACE_MESSAGE)
129
139
  lock.synchronize do
130
140
  traces << { tuid: tuid,
131
- type: 'TraceMessage',
141
+ type: type,
132
142
  order_num: order_num,
133
143
  nesting_level: 0,
134
144
  message: message,
@@ -182,11 +192,17 @@ module Callstacking
182
192
  url
183
193
  end
184
194
 
185
- def complete_request(trace_id, tuid, method, controller, action, format, original_url, traces, max_trace_entries)
195
+ def complete_request(trace_id, tuid, exception, method, controller,
196
+ action, format, original_url, traces, max_trace_entries)
186
197
  return if do_not_track_request?(original_url, format)
187
198
 
188
- create_message(tuid, completed_request_message(method, controller, action, format),
189
- spans.increment_order_num, traces)
199
+ if exception.present?
200
+ create_message(tuid, exception_message(exception, method, controller, action, format),
201
+ spans.increment_order_num, traces, TRACE_EXCEPTION)
202
+ else
203
+ create_message(tuid, completed_request_message(method, controller, action, format),
204
+ spans.increment_order_num, traces)
205
+ end
190
206
 
191
207
  send_traces!(trace_id, traces[0..max_trace_entries])
192
208
  end
@@ -1,5 +1,5 @@
1
1
  module Callstacking
2
2
  module Rails
3
- VERSION = "0.1.35"
3
+ VERSION = "0.1.37"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callstacking-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Jones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2023-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails