appmap 0.90.1 → 0.92.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8c53e191f43fe539ca2fd9381bf690597ec89b96ab1848680344b3d52a1b8f6
4
- data.tar.gz: 1ee5593abdd95aefcc4b10a9ac717ea281e27885a4fd6a89fa0dc10ea5c2f66a
3
+ metadata.gz: 78d8c3cf7967b06242390e3d11ddd24c5cf29fd70244b93b2bf170323747b762
4
+ data.tar.gz: 10147c54915b55d8a67723d1721c31a9e809983bb9b0012cdb2f480e9dcf3695
5
5
  SHA512:
6
- metadata.gz: c718347cfdb809cdfbdd46bee5399a98e6100d5afc3120e060f297d6f950227f1e263fab6baf5b705c4ec3573ef2f9aa1d1e96aff2053e120de1a2cc7dc4a55e
7
- data.tar.gz: 89e90d35c06c1ae3db76bb58481dce70420081c92e386dc1b75922fbe53fcdac2609f157967fdacf476e3ed9c5f5c79bcfe83a88e56f84ab14aebaaab36fccfe
6
+ metadata.gz: 7ce433191ab8e3699feeb995951df0653ef9b89bb11edc7ca671b80011a2af1818e08c22eaa4f0777ec364be9e6e9d8bfec84099ff518d43768fb710e005b681
7
+ data.tar.gz: f0c99190697605e71658d9c3c602913954604396c7fb3cc31db09edb1b4cb8bdd1fb4f184e762ff15458b64e5078cd69ac04c324eddd0b4d83e28e3c2b324bb0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ # [0.92.0](https://github.com/applandinc/appmap-ruby/compare/v0.91.0...v0.92.0) (2022-09-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Detect Rails via Rails::Railtie ([cf83f00](https://github.com/applandinc/appmap-ruby/commit/cf83f005e0a85d016f864c0ad2f1dfa1af2fe6b9))
7
+
8
+
9
+ ### Features
10
+
11
+ * Don't auto-enable requests recording in 'test' ([30413cd](https://github.com/applandinc/appmap-ruby/commit/30413cdc23b3851e8e1272d30063e463b4b23aba))
12
+ * Enable recording for known environments ([6c59c8a](https://github.com/applandinc/appmap-ruby/commit/6c59c8a5a0b61c19cec185d7406b148846ac5c24))
13
+ * Use APPMAP=true to flag library loading ([9900631](https://github.com/applandinc/appmap-ruby/commit/9900631c07165a877704b7d7fd73857ccf9e32b3))
14
+
15
+ # [0.91.0](https://github.com/applandinc/appmap-ruby/compare/v0.90.1...v0.91.0) (2022-09-19)
16
+
17
+
18
+ ### Features
19
+
20
+ * Emit metadata.recorder.type ([6358669](https://github.com/applandinc/appmap-ruby/commit/6358669d5dc5123a613b18301519dac709614406))
21
+
1
22
  ## [0.90.1](https://github.com/applandinc/appmap-ruby/compare/v0.90.0...v0.90.1) (2022-09-19)
2
23
 
3
24
 
data/lib/appmap/agent.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'open'
9
9
 
10
10
  # load extension
11
11
  require_relative 'appmap'
12
+ require_relative './detect_enabled'
12
13
 
13
14
  module AppMap
14
15
  class << self
@@ -114,5 +115,9 @@ module AppMap
114
115
  def explain_queries?
115
116
  ENV['APPMAP_EXPLAIN_QUERIES'] == 'true'
116
117
  end
118
+
119
+ def recording_enabled?(recording_method = nil)
120
+ DetectEnabled.new(recording_method).enabled?
121
+ end
117
122
  end
118
123
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'appmap'
3
4
  require 'appmap/util'
4
5
  require 'fileutils'
5
6
 
@@ -55,7 +56,7 @@ module AppMap
55
56
  end
56
57
 
57
58
  def enabled?
58
- ENV['APPMAP'] == 'true'
59
+ AppMap.recording_enabled?(:cucumber)
59
60
  end
60
61
 
61
62
  def run
@@ -92,7 +93,8 @@ module AppMap
92
93
  'version' => Gem.loaded_specs['cucumber']&.version&.to_s
93
94
  }
94
95
  m['recorder'] = {
95
- 'name' => 'cucumber'
96
+ 'name' => 'cucumber',
97
+ 'type' => 'tests'
96
98
  }
97
99
  end
98
100
  end
@@ -0,0 +1,111 @@
1
+ require_relative './recording_methods'
2
+
3
+ module AppMap
4
+ # Detects whether AppMap recording should be enabled. This test can be performed generally, or for
5
+ # a particular recording method. Recording can be enabled explicitly, for example via APPMAP=true,
6
+ # or it can be enabled implicitly, by running in a dev or test web application environment. Recording
7
+ # can also disabled explicitly, using environment variables.
8
+ class DetectEnabled
9
+ @@detected_for_method = {}
10
+
11
+ class << self
12
+ def clear_cache
13
+ @@detected_for_method = {}
14
+ end
15
+ end
16
+
17
+ def initialize(recording_method)
18
+ @recording_method = recording_method
19
+ end
20
+
21
+ def enabled?
22
+ unless @@detected_for_method[@recording_method].nil?
23
+ return @@detected_for_method[@recording_method]
24
+ end
25
+
26
+ raise "Unrecognized recording method: #{@recording_method}" if @recording_method && !AppMap::RECORDING_METHODS.member?(@recording_method)
27
+
28
+ message, enabled, enabled_by_env = detect_enabled
29
+
30
+ @@detected_for_method[@recording_method] = enabled
31
+
32
+ if @recording_method
33
+ if enabled && enabled_by_app_env?
34
+ warn AppMap::Util.color("AppMap #{@recording_method.nil? ? '' : "#{@recording_method} "}recording is enabled because #{message}", :magenta)
35
+ end
36
+ end
37
+
38
+ enabled
39
+ end
40
+
41
+ def detect_enabled
42
+ detection_functions = %i[globally_disabled? recording_method_disabled? enabled_by_app_env? recording_method_enabled? globally_enabled?]
43
+
44
+ message, enabled = []
45
+ while enabled.nil? && !detection_functions.empty?
46
+ message, enabled = method(detection_functions.shift).call
47
+ end
48
+
49
+ unless enabled.nil?
50
+ _, enabled_by_env = enabled_by_app_env?
51
+ return [ message, enabled, enabled_by_env ]
52
+ else
53
+ return [ 'it is not enabled by any configuration or framework', false, false ]
54
+ end
55
+ end
56
+
57
+ def enabled_by_app_env?
58
+ env_name, app_env = detect_app_env
59
+ if %i[rspec minitest cucumber].member?(@recording_method)
60
+ return [ "#{env_name} is '#{app_env}'", true ] if app_env == 'test'
61
+ end
62
+
63
+ if @recording_method.nil?
64
+ return [ "#{env_name} is '#{app_env}'", true ] if %w[test development].member?(app_env)
65
+ end
66
+
67
+ if %i[remote requests].member?(@recording_method)
68
+ return [ "#{env_name} is '#{app_env}'", true ] if app_env == 'development'
69
+ end
70
+ end
71
+
72
+ def detect_app_env
73
+ if rails_env
74
+ return [ 'RAILS_ENV', rails_env ]
75
+ elsif ENV['APP_ENV']
76
+ return [ 'APP_ENV', ENV['APP_ENV']]
77
+ end
78
+ end
79
+
80
+ def globally_enabled?
81
+ # Don't auto-enable request recording in the 'test' environment, because users probably don't want
82
+ # AppMaps of both test cases and requests. Requests recording can always be enabled by APPMAP_RECORD_REQUESTS=true.
83
+ requests_recording_in_test = -> () { [ :requests ].member?(@recording_method) && detect_app_env == 'test' }
84
+ [ 'APPMAP=true', true ] if ENV['APPMAP'] == 'true' && !requests_recording_in_test.()
85
+ end
86
+
87
+ def globally_disabled?
88
+ [ 'APPMAP=false', false ] if ENV['APPMAP'] == 'false'
89
+ end
90
+
91
+ def recording_method_disabled?
92
+ return false unless @recording_method
93
+
94
+ env_var = [ 'APPMAP', 'RECORD', @recording_method.upcase ].join('_')
95
+ [ "#{[ 'APPMAP', 'RECORD', @recording_method.upcase ].join('_')}=false", false ] if ENV[env_var] == 'false'
96
+ end
97
+
98
+ def recording_method_enabled?
99
+ return false unless @recording_method
100
+
101
+ env_var = [ 'APPMAP', 'RECORD', @recording_method.upcase ].join('_')
102
+ [ "#{[ 'APPMAP', 'RECORD', @recording_method.upcase ].join('_')}=true", true ] if ENV[env_var] == 'true'
103
+ end
104
+
105
+ def rails_env
106
+ return Rails.env if defined?(::Rails::Railtie)
107
+
108
+ return ENV['RAILS_ENV']
109
+ end
110
+ end
111
+ end
@@ -63,7 +63,8 @@ module AppMap
63
63
 
64
64
  metadata = AppMap.detect_metadata
65
65
  metadata[:recorder] = {
66
- name: 'remote_recording'
66
+ name: 'remote_recording',
67
+ type: 'remote'
67
68
  }
68
69
 
69
70
  response = JSON.generate \
@@ -81,7 +82,7 @@ module AppMap
81
82
  # 0
82
83
 
83
84
  req = Rack::Request.new(env)
84
- return handle_record_request(req) if req.path == '/_appmap/record'
85
+ return handle_record_request(req) if AppMap.recording_enabled?(:remote) && req.path == '/_appmap/record'
85
86
 
86
87
  start_time = Time.now
87
88
  # Support multi-threaded web server such as Puma by recording each thread
@@ -103,7 +104,8 @@ module AppMap
103
104
  metadata[:name] = appmap_name
104
105
  metadata[:timestamp] = start_time.to_f
105
106
  metadata[:recorder] = {
106
- name: 'record_requests'
107
+ name: 'rack',
108
+ type: 'requests'
107
109
  }
108
110
 
109
111
  appmap = {
@@ -148,7 +150,7 @@ module AppMap
148
150
  end
149
151
 
150
152
  def record_all_requests?
151
- ENV['APPMAP_RECORD_REQUESTS'] == 'true'
153
+ AppMap.recording_enabled?(:requests)
152
154
  end
153
155
 
154
156
  def recording?
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'appmap'
3
4
  require 'appmap/util'
4
5
  require 'fileutils'
5
6
  require 'active_support'
@@ -101,7 +102,8 @@ module AppMap
101
102
  version: Gem.loaded_specs['minitest']&.version&.to_s
102
103
  }
103
104
  m[:recorder] = {
104
- name: 'minitest'
105
+ name: 'minitest',
106
+ type: 'tests'
105
107
  }
106
108
  m[:test_status] = test_status
107
109
  if exception
@@ -124,7 +126,7 @@ module AppMap
124
126
  end
125
127
 
126
128
  def enabled?
127
- ENV['APPMAP'] == 'true'
129
+ AppMap.recording_enabled?(:minitest)
128
130
  end
129
131
 
130
132
  def run
@@ -4,6 +4,11 @@ module AppMap
4
4
  # Railtie connects the AppMap recorder to Rails-specific features.
5
5
  class Railtie < ::Rails::Railtie
6
6
  initializer 'appmap.remote_recording' do
7
+ # Indicate early in the log when these methods are enabled.
8
+ %i[remote requests].each do |recording_method|
9
+ AppMap.recording_enabled?(recording_method)
10
+ end
11
+
7
12
  require 'appmap/middleware/remote_recording'
8
13
  Rails.application.config.middleware.insert_before \
9
14
  ActionDispatch::Executor,
@@ -29,4 +34,4 @@ module AppMap
29
34
  end
30
35
  end
31
36
  end
32
- end if ENV['APPMAP'] == 'true'
37
+ end if AppMap.recording_enabled?
data/lib/appmap/record.rb CHANGED
@@ -14,7 +14,8 @@ at_exit do
14
14
 
15
15
  metadata = AppMap.detect_metadata
16
16
  metadata[:recorder] = {
17
- name: 'record_process'
17
+ name: 'record_process',
18
+ type: 'process'
18
19
  }
19
20
 
20
21
  appmap = {
@@ -0,0 +1,3 @@
1
+ module AppMap
2
+ RECORDING_METHODS = %i[rspec minitest cucumber remote requests].freeze
3
+ end
data/lib/appmap/rspec.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'appmap'
3
4
  require 'appmap/util'
4
5
  require 'set'
5
6
  require 'fileutils'
6
7
 
7
8
  module AppMap
8
- # Integration of AppMap with RSpec. When enabled with APPMAP=true, the AppMap tracer will
9
- # be activated around each scenario which has the metadata key `:appmap`.
10
9
  module RSpec
11
10
  APPMAP_OUTPUT_DIR = 'tmp/appmap/rspec'
12
11
  LOG = false
@@ -192,7 +191,8 @@ module AppMap
192
191
  version: Gem.loaded_specs['rspec-core']&.version&.to_s
193
192
  }
194
193
  m[:recorder] = {
195
- name: 'rspec'
194
+ name: 'rspec',
195
+ type: 'tests'
196
196
  }
197
197
  m[:test_status] = test_status
198
198
  if exception
@@ -215,7 +215,7 @@ module AppMap
215
215
  end
216
216
 
217
217
  def enabled?
218
- ENV['APPMAP'] == 'true'
218
+ AppMap.recording_enabled?(:rspec)
219
219
  end
220
220
 
221
221
  def run
@@ -226,7 +226,6 @@ module AppMap
226
226
  end
227
227
 
228
228
  if AppMap::RSpec.enabled?
229
- require 'appmap'
230
229
  require 'active_support/inflector/transliterate'
231
230
  require 'rspec/core'
232
231
  require 'rspec/core/example'
@@ -16,7 +16,7 @@ module AppMap
16
16
  command: {
17
17
  program: 'bundle',
18
18
  args: %w[exec rspec] + integration_test_paths[:rspec].map { |path| "./#{path}" },
19
- environment: { APPMAP: 'true', DISABLE_SPRING: 'true' }
19
+ environment: { }
20
20
  }
21
21
  }
22
22
  end
@@ -30,7 +30,7 @@ module AppMap
30
30
  command: {
31
31
  program: 'bundle',
32
32
  args: %w[exec cucumber],
33
- environment: { APPMAP: 'true', DISABLE_SPRING: 'true' }
33
+ environment: { }
34
34
  }
35
35
  }
36
36
  end
@@ -48,7 +48,7 @@ module AppMap
48
48
  command: {
49
49
  program: 'bundle',
50
50
  args: %w[exec rails test] + integration_test_paths[:minitest].map { |path| "./#{path}" },
51
- environment: { APPMAP: 'true', DISABLE_SPRING: 'true' }
51
+ environment: { }
52
52
  }
53
53
  }
54
54
  ]
@@ -59,7 +59,7 @@ module AppMap
59
59
  command: {
60
60
  program: 'bundle',
61
61
  args: ['exec', 'ruby', "./#{path}"],
62
- environment: { APPMAP: 'true', DISABLE_SPRING: 'true' }
62
+ environment: { }
63
63
  }
64
64
  }
65
65
  end
@@ -3,9 +3,9 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.90.1'
6
+ VERSION = '0.92.0'
7
7
 
8
- APPMAP_FORMAT_VERSION = '1.7.0'
8
+ APPMAP_FORMAT_VERSION = '1.9.0'
9
9
 
10
10
  SUPPORTED_RUBY_VERSIONS = %w[2.5 2.6 2.7 3.0 3.1].freeze
11
11
 
data/lib/appmap.rb CHANGED
@@ -57,7 +57,7 @@ lambda do
57
57
  end
58
58
  end.enable
59
59
 
60
- if defined?(::Rails)
60
+ if defined?(::Rails::Railtie)
61
61
  require 'appmap/railtie'
62
62
  end
63
63
 
@@ -76,4 +76,4 @@ lambda do
76
76
 
77
77
  end.call unless ENV['APPMAP_AUTOREQUIRE'] == 'false'
78
78
 
79
- AppMap.initialize_configuration if ENV['APPMAP'] == 'true' && ENV['APPMAP_INITIALIZE'] != 'false'
79
+ AppMap.initialize_configuration if AppMap.recording_enabled? && ENV['APPMAP_INITIALIZE'] != 'false'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.90.1
4
+ version: 0.92.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
@@ -378,6 +378,7 @@ files:
378
378
  - lib/appmap/depends/test_file_inspector.rb
379
379
  - lib/appmap/depends/test_runner.rb
380
380
  - lib/appmap/depends/util.rb
381
+ - lib/appmap/detect_enabled.rb
381
382
  - lib/appmap/event.rb
382
383
  - lib/appmap/gem_hooks/actionpack.yml
383
384
  - lib/appmap/gem_hooks/actionview.yml
@@ -415,6 +416,7 @@ files:
415
416
  - lib/appmap/open.rb
416
417
  - lib/appmap/railtie.rb
417
418
  - lib/appmap/record.rb
419
+ - lib/appmap/recording_methods.rb
418
420
  - lib/appmap/rspec.rb
419
421
  - lib/appmap/service/config_analyzer.rb
420
422
  - lib/appmap/service/guesser.rb