action_tracer 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6886a0826048909019cd75d52f9ea682833b56addca3f7cd7636e313fe1c79b
4
- data.tar.gz: e2f352937846c839de2837534f5b60be2c210623182d1a24d4d06323d35c8e0f
3
+ metadata.gz: 833bc9f0ef13dc38365b9fed4b4ec1e6d31e3836ae07a44f366e2eb4d198e2d1
4
+ data.tar.gz: ae5c7acf603370367d3f77bd7999cfdc51ddce60a886951c4f3b05ca2c4ad442
5
5
  SHA512:
6
- metadata.gz: '075917e7971d4b75385e425ca49428fc63093cfb4496fe96fd30d84e8e23a382d5ffe77a8b8c4950031528f2f67d01f8b967d44216104add9399dc63d3572a21'
7
- data.tar.gz: fabc09fb2d4911362b9c732603e9901cfda1807c01a682b5c69fd2c40932707009faa2836f21e4dbf797a9bb10bc5e689662442ef8946de94190e94f4dfec9d0
6
+ metadata.gz: 9a8db105412a32d90e32e5f76947b8740dbc0dbdeebca1981304e1d09bd6922778a02f72e6d62c341df003eef120230bd7d0530b1eb8c797ee4c26d78d8fcc43
7
+ data.tar.gz: a1a9685cb4d7e8c3fad3560dd645c0ac7044ec3c1824f9a7abe75d4b0b123d905ea4713344231fef1a0ce78cbb5ac121fac22bbf6e92a939868a89e750102a73
@@ -0,0 +1,4 @@
1
+ ## 0.2.0
2
+
3
+ * Stop using TracePoint and just override ActiveSupport::Callbacks::CallTemplate
4
+ We don't necessary passing environment variable anymore!
data/README.md CHANGED
@@ -15,31 +15,7 @@ Support for Rails application with ActiveController::API is comming soon.
15
15
 
16
16
  ## Usage
17
17
 
18
- Run rails server or run rspec with `ACTION_TRACER=1` to log actions and filters for `log/action_tracer.log`.
19
-
20
- ```bash
21
- $ ACTION_TRACER=1 rails server
22
- ```
23
-
24
- You can also run rspec for your request specs.
25
-
26
- ```bash
27
- $ ACTION_TRACER=1 rspec
28
- ```
29
-
30
- If you use docker-compose, pass environment variable:
31
-
32
- ```yml
33
- version: 3
34
- services:
35
- web:
36
- build: .
37
- command: bundle exec rails s -p 3000
38
- environment:
39
- ACTION_TRACER: 1
40
- volumes:
41
- # ...
42
- ```
18
+ Run rails server or run rspec and check `log/action_tracer.log`.
43
19
 
44
20
  ### Example
45
21
 
@@ -78,7 +54,7 @@ private
78
54
  end
79
55
  ```
80
56
 
81
- When you run rails server with `ACTION_TRACER=1` and access `/awesome` (action is `#index`),
57
+ When you run rails server and access `/awesome` (action is `#index`),
82
58
  it will put logs for `log/action_tracer.log` like this:
83
59
 
84
60
  ```log
@@ -124,9 +100,6 @@ We can't recgnize the filter is actually executed or not.
124
100
  ## CommingFeatures
125
101
 
126
102
  - Support for Rails application with ActiveController::API
127
- - Add non-checking mode
128
- - Memorizing filters are applied or not is very costly.
129
- Add non-checking mode filters are actually applied or not.
130
103
  - Log rotate
131
104
 
132
105
  ## Contributing
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_tracer/version"
4
- require "action_tracer/railtie" if ENV["ACTION_TRACER"]
4
+ require "action_tracer/railtie"
5
5
  require "action_tracer/filters"
6
6
  require "action_tracer/logger"
7
7
  require "action_tracer/action_tracer"
@@ -5,9 +5,7 @@ module ActionTracer
5
5
 
6
6
  class << self
7
7
  def log(controller)
8
- filter_collector.enable
9
8
  result = yield
10
- filter_collector.disable
11
9
  Filters.build(controller).print
12
10
  applied_filters.clear
13
11
  ActionTracer.logger.info ""
@@ -15,25 +13,6 @@ module ActionTracer
15
13
  result
16
14
  end
17
15
 
18
- def filter_collector
19
- @filter_collector ||= TracePoint.new(:return) do |tp|
20
- # NOTE: ActiveSupport::Callbacks::CallTemplate is a private class
21
- if tp.method_id == :expand && tp.defined_class == ActiveSupport::Callbacks::CallTemplate
22
- if tp.return_value&.first.is_a? ActionController::Base
23
- # target, block, method, *arguments = tp.return_value
24
- case tp.return_value[2]
25
- when :instance_exec # filter is a proc
26
- applied_filters << tp.return_value[1]
27
- when String # filter is an object
28
- applied_filters << tp.return_value[1]
29
- when Symbol # filter is a method
30
- applied_filters << tp.return_value[2]
31
- end
32
- end
33
- end
34
- end
35
- end
36
-
37
16
  def applied_filters
38
17
  @applied_filters ||= []
39
18
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionTracer
4
+ APPLIED = { true => "APPLIED", false => "NO_APPLIED", unrecognized: "UNRECOGNIZED", action: "ACTION" }.freeze
5
+
4
6
  class Filter
5
- APPLIED = { true => "APPLIED", false => "NO_APPLIED" }.freeze
6
7
  PROC = :Proc
7
8
  attr_reader :applied
8
9
 
@@ -16,7 +17,7 @@ module ActionTracer
16
17
  if @method.respond_to? :source_location
17
18
  [APPLIED[@applied], @filter, *@method.source_location]
18
19
  else
19
- ["UNRECOGNIZED", @method]
20
+ [APPLIED[:unrecognized], @method]
20
21
  end
21
22
  end
22
23
  end
@@ -42,7 +43,7 @@ module ActionTracer
42
43
 
43
44
  def print
44
45
  invoked_before.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
45
- ActionTracer.logger.info ["ACTION", @action.name, *@action.source_location]
46
+ ActionTracer.logger.info [APPLIED[:action], @action.name, *@action.source_location]
46
47
  invoked_after.map(&:to_a).reverse_each { |filter| ActionTracer.logger.info filter }
47
48
  end
48
49
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTracer
4
+ module MonkeyPatches
5
+ module ActiveSupport
6
+ module Callbacks
7
+ module CallTemplate
8
+ def expand(*)
9
+ target, block, method, *arguments = super
10
+ if target.is_a? ActionController::Base
11
+ case method
12
+ when :instance_exec # filter is a proc
13
+ ActionTracer.applied_filters << block
14
+ when String # filter is an object
15
+ ActionTracer.applied_filters << block
16
+ when Symbol # filter is a method
17
+ ActionTracer.applied_filters << method
18
+ end
19
+ end
20
+
21
+ [target, block, method, *arguments]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -22,6 +22,8 @@ module ActionTracer
22
22
  class Railtie < ::Rails::Railtie
23
23
  initializer "action_tracer" do
24
24
  ActiveSupport.on_load(:action_controller) do
25
+ require "action_tracer/monkey_patches/active_support/callbacks"
26
+ ::ActiveSupport::Callbacks::CallTemplate.prepend ActionTracer::MonkeyPatches::ActiveSupport::Callbacks::CallTemplate
25
27
  require "action_tracer/monkey_patches/abstract_controller/callbacks"
26
28
  ::ActionController::Base.prepend ActionTracer::MonkeyPatches::AbstractController::Callbacks
27
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionTracer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makicamel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -106,6 +106,7 @@ files:
106
106
  - lib/action_tracer/filters.rb
107
107
  - lib/action_tracer/logger.rb
108
108
  - lib/action_tracer/monkey_patches/abstract_controller/callbacks.rb
109
+ - lib/action_tracer/monkey_patches/active_support/callbacks.rb
109
110
  - lib/action_tracer/railtie.rb
110
111
  - lib/action_tracer/version.rb
111
112
  homepage: https://github.com/makicamel/action_tracer