rails_tracepoint_stack 0.3.4 → 0.4.0

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.
@@ -0,0 +1,50 @@
1
+ module RailsTracepointStack
2
+ # Shrinks an already-serialized value so one fat argument (a big payload, a
3
+ # long SQL string, a loaded association) cannot dominate the output. Runs
4
+ # over the plain structures LogFormatter.safe_value produces, so it only
5
+ # ever sees strings, numbers, booleans, nil, arrays and hashes.
6
+ module Truncator
7
+ ELLIPSIS = "…".freeze
8
+
9
+ def self.call(value, limits)
10
+ case value
11
+ when String then truncate_string(value, limits)
12
+ when Array then truncate_array(value, limits)
13
+ when Hash then truncate_hash(value, limits)
14
+ else value
15
+ end
16
+ end
17
+
18
+ def self.truncate_string(value, limits)
19
+ max = limits.max_string_length
20
+ return value if max.nil? || value.length <= max
21
+
22
+ "#{value[0, max]}#{ELLIPSIS} (#{value.length} chars)"
23
+ end
24
+
25
+ def self.truncate_array(value, limits)
26
+ max = limits.max_collection_size
27
+ kept = (max.nil? || value.length <= max) ? value : value.first(max)
28
+ result = kept.map { |item| call(item, limits) }
29
+
30
+ return result if kept.length == value.length
31
+
32
+ result << "(+#{value.length - kept.length} more)"
33
+ end
34
+
35
+ def self.truncate_hash(value, limits)
36
+ max = limits.max_collection_size
37
+ dropped = (max.nil? || value.size <= max) ? 0 : value.size - max
38
+ kept = dropped.zero? ? value : value.first(max).to_h
39
+
40
+ result = kept.each_with_object({}) do |(key, item), memo|
41
+ memo[key] = call(item, limits)
42
+ end
43
+
44
+ return result if dropped.zero?
45
+
46
+ result[ELLIPSIS] = "(+#{dropped} more)"
47
+ result
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsTracepointStack
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  require 'rails_tracepoint_stack/configuration'
2
2
  require 'rails_tracepoint_stack/log_formatter'
3
3
  require 'rails_tracepoint_stack/tracer'
4
+ require 'rails_tracepoint_stack/limits'
5
+ require 'rails_tracepoint_stack/skill_installer'
6
+ require 'rails_tracepoint_stack/sink/collector'
7
+ require 'rails_tracepoint_stack/trace_session'
4
8
 
5
9
  $rails_tracer_rtps = nil
6
10
 
@@ -17,10 +21,41 @@ module RailsTracepointStack
17
21
  yield(configuration)
18
22
  end
19
23
 
24
+ CAPTURE_EVENTS = [:call, :return, :raise].freeze
25
+
26
+ # Traces a block and hands back everything that happened inside it, instead
27
+ # of writing to a log. Meant to be run as a one-off: capture, read, done.
28
+ def self.capture(threads: :current, **limit_options)
29
+ raise ArgumentError, "Block not given to #capture" unless block_given?
30
+
31
+ collector = RailsTracepointStack::Sink::Collector.new(
32
+ limits: RailsTracepointStack::Limits.new(**limit_options)
33
+ )
34
+ session = collector.session
35
+ tracer = RailsTracepointStack::Tracer.new(
36
+ sink: collector,
37
+ events: CAPTURE_EVENTS,
38
+ thread: (threads == :all) ? nil : Thread.current
39
+ )
40
+
41
+ tracer.enable
42
+ begin
43
+ session.result = yield(session)
44
+ rescue Exception => error
45
+ session.error = error
46
+ raise
47
+ ensure
48
+ tracer.disable
49
+ session.filtered_count = tracer.filtered_count
50
+ end
51
+
52
+ session
53
+ end
54
+
20
55
  def self.enable_trace
21
56
  raise ArgumentError, "Block not given to #enable_trace" unless block_given?
22
57
 
23
- tracer = RailsTracepointStack::Tracer.new.tracer
58
+ tracer = RailsTracepointStack::Tracer.new
24
59
  tracer.enable
25
60
  yield
26
61
  ensure
@@ -28,8 +63,8 @@ module RailsTracepointStack
28
63
  end
29
64
  end
30
65
 
31
- if ENV.fetch('RAILS_TRACEPOINT_STACK_ENABLED', 'false') == 'true'
32
- $rails_tracer_rtps = RailsTracepointStack::Tracer.new.tracer
66
+ if ENV.fetch("RAILS_TRACEPOINT_STACK_ENABLED", "false") == "true"
67
+ $rails_tracer_rtps = RailsTracepointStack::Tracer.new
33
68
  $rails_tracer_rtps.enable
34
69
 
35
70
  at_exit do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_tracepoint_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Daniel Pohlod
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-03 00:00:00.000000000 Z
11
+ date: 2026-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -50,35 +50,72 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 13.0.0
53
- description: A formatted output of all methods called in your rails application of
54
- code created by the developer, with the complete path to the class/module, including
55
- passed params.
53
+ - !ruby/object:Gem::Dependency
54
+ name: standard
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.39'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.39.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.39'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.39.1
73
+ description: Traces a block of your Rails app and returns the call tree of your own
74
+ code - arguments, return values, raised exceptions and call depth - with gems, the
75
+ framework and stdlib filtered out. Bounded output meant to be read directly, by
76
+ a developer or by an AI coding agent debugging the app.
56
77
  email: carlospohlod@gmail.com
57
78
  executables: []
58
79
  extensions: []
59
80
  extra_rdoc_files: []
60
81
  files:
82
+ - README.md
83
+ - changelog.md
84
+ - lib/generators/rails_tracepoint_stack/install/install_generator.rb
61
85
  - lib/rails_tracepoint_stack.rb
62
86
  - lib/rails_tracepoint_stack/configuration.rb
87
+ - lib/rails_tracepoint_stack/depth_tracker.rb
63
88
  - lib/rails_tracepoint_stack/filter/custom_trace_selector_filter.rb
64
89
  - lib/rails_tracepoint_stack/filter/gem_path.rb
65
90
  - lib/rails_tracepoint_stack/filter/rb_config.rb
66
91
  - lib/rails_tracepoint_stack/filter/trace_from_dependencies_filter.rb
67
92
  - lib/rails_tracepoint_stack/filter/trace_from_ruby_code_filter.rb
68
93
  - lib/rails_tracepoint_stack/filter/trace_to_ignore_filter.rb
94
+ - lib/rails_tracepoint_stack/limits.rb
69
95
  - lib/rails_tracepoint_stack/log_formatter.rb
70
96
  - lib/rails_tracepoint_stack/logger.rb
97
+ - lib/rails_tracepoint_stack/renderer/summary.rb
98
+ - lib/rails_tracepoint_stack/renderer/tree.rb
99
+ - lib/rails_tracepoint_stack/sink/collector.rb
100
+ - lib/rails_tracepoint_stack/sink/log.rb
101
+ - lib/rails_tracepoint_stack/skill_installer.rb
102
+ - lib/rails_tracepoint_stack/templates/skill.md
71
103
  - lib/rails_tracepoint_stack/trace.rb
72
104
  - lib/rails_tracepoint_stack/trace_filter.rb
105
+ - lib/rails_tracepoint_stack/trace_record.rb
106
+ - lib/rails_tracepoint_stack/trace_session.rb
73
107
  - lib/rails_tracepoint_stack/tracer.rb
108
+ - lib/rails_tracepoint_stack/truncator.rb
74
109
  - lib/rails_tracepoint_stack/version.rb
75
- homepage: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/
110
+ homepage: https://carlosdanielpohlod.github.io/rails_tracepoint_stack/
76
111
  licenses:
77
112
  - MIT
78
113
  metadata:
79
- documentation_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/
114
+ source_code_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack
115
+ documentation_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack#readme
116
+ bug_tracker_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/issues
80
117
  changelog_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/blob/main/changelog.md
81
- post_install_message:
118
+ post_install_message:
82
119
  rdoc_options: []
83
120
  require_paths:
84
121
  - lib
@@ -93,8 +130,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
130
  - !ruby/object:Gem::Version
94
131
  version: '0'
95
132
  requirements: []
96
- rubygems_version: 3.4.10
97
- signing_key:
133
+ rubygems_version: 3.4.19
134
+ signing_key:
98
135
  specification_version: 4
99
- summary: Get a complete stack trace for your code on a Rails application.
136
+ summary: 'Runtime call tree for a Rails app: which methods ran, with what params,
137
+ and what they returned.'
100
138
  test_files: []