appmap 0.91.0 → 0.92.1

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: 4d721301c87647a2778b1019519a7ada3fc225761b32149070ee38d8e47c5643
4
- data.tar.gz: b4a130739d8974a3adbe44a9020618e9f88530174de19e8aaa0713dad23336c4
3
+ metadata.gz: f527f92e73d7e71cf5a4e9db3b71c570b39443ad0788bc2c6f4b4bae4bb215ba
4
+ data.tar.gz: 6604ce77790645d5c5a60d37a2bc1116952909fe29856ea9fb36bac29d992d81
5
5
  SHA512:
6
- metadata.gz: 9f0778dc18e12f668bc072b94f21f61f1310c6d0163531e7e8407fd5e45d64d9a2e1b2a9d4c0cf98c1ba3f31697ca38ee50461f55b293893442a7b19f515ac3a
7
- data.tar.gz: 9469680e79ccf0e8a43967c1c6d0104c48d35399fd39b205bfc9d3c41f32f2469d527989f38e965f80e00f320cfce9026c124ed775f27ba773bf58d449083d6c
6
+ metadata.gz: 841907ab84538b09c9f83509d3c65dcd6d3b0be92e452a3558194fd33a8c90336f4f8294be91ac94a8631546acc89bef91807a451a546c3c1d9408110268e237
7
+ data.tar.gz: 715e6d1e540a89c660f0d3a9794b0c199356b1557fc5921226a422b78eff9c62f6b696cd1d231f0c25d06b82c417f5fef4b9e613b564146a50779b6e4d4d6910
@@ -12,5 +12,5 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/add-to-project@main
14
14
  with:
15
- project-url: https://github.com/orgs/applandinc/projects/15
15
+ project-url: https://github.com/orgs/getappmap/projects/15
16
16
  github-token: ${{ secrets.ADD_TO_PROJECT_BOARD_PAT }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.92.1](https://github.com/getappmap/appmap-ruby/compare/v0.92.0...v0.92.1) (2022-09-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Drop database server version ([e52f210](https://github.com/getappmap/appmap-ruby/commit/e52f210baa26be49232003c224e4ffee19be823d))
7
+
8
+ # [0.92.0](https://github.com/applandinc/appmap-ruby/compare/v0.91.0...v0.92.0) (2022-09-19)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Detect Rails via Rails::Railtie ([cf83f00](https://github.com/applandinc/appmap-ruby/commit/cf83f005e0a85d016f864c0ad2f1dfa1af2fe6b9))
14
+
15
+
16
+ ### Features
17
+
18
+ * Don't auto-enable requests recording in 'test' ([30413cd](https://github.com/applandinc/appmap-ruby/commit/30413cdc23b3851e8e1272d30063e463b4b23aba))
19
+ * Enable recording for known environments ([6c59c8a](https://github.com/applandinc/appmap-ruby/commit/6c59c8a5a0b61c19cec185d7406b148846ac5c24))
20
+ * Use APPMAP=true to flag library loading ([9900631](https://github.com/applandinc/appmap-ruby/commit/9900631c07165a877704b7d7fd73857ccf9e32b3))
21
+
1
22
  # [0.91.0](https://github.com/applandinc/appmap-ruby/compare/v0.90.1...v0.91.0) (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
@@ -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
@@ -75,7 +75,6 @@ module AppMap
75
75
  end
76
76
  end
77
77
 
78
- payload[:server_version] = examiner.server_version
79
78
  payload[:database_type] = examiner.database_type.to_s
80
79
  end
81
80
 
@@ -92,6 +91,8 @@ module AppMap
92
91
 
93
92
  class SequelExaminer
94
93
  def server_version
94
+ # Queries the database, therefore this is pretty unsafe to do inside of a hook.
95
+ # As a result, this is not being used at the moment.
95
96
  Sequel::Model.db.server_version
96
97
  end
97
98
 
@@ -82,7 +82,7 @@ module AppMap
82
82
  # 0
83
83
 
84
84
  req = Rack::Request.new(env)
85
- 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'
86
86
 
87
87
  start_time = Time.now
88
88
  # Support multi-threaded web server such as Puma by recording each thread
@@ -150,7 +150,7 @@ module AppMap
150
150
  end
151
151
 
152
152
  def record_all_requests?
153
- ENV['APPMAP_RECORD_REQUESTS'] == 'true'
153
+ AppMap.recording_enabled?(:requests)
154
154
  end
155
155
 
156
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'
@@ -125,7 +126,7 @@ module AppMap
125
126
  end
126
127
 
127
128
  def enabled?
128
- ENV['APPMAP'] == 'true'
129
+ AppMap.recording_enabled?(:minitest)
129
130
  end
130
131
 
131
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?
@@ -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
@@ -216,7 +215,7 @@ module AppMap
216
215
  end
217
216
 
218
217
  def enabled?
219
- ENV['APPMAP'] == 'true'
218
+ AppMap.recording_enabled?(:rspec)
220
219
  end
221
220
 
222
221
  def run
@@ -227,7 +226,6 @@ module AppMap
227
226
  end
228
227
 
229
228
  if AppMap::RSpec.enabled?
230
- require 'appmap'
231
229
  require 'active_support/inflector/transliterate'
232
230
  require 'rspec/core'
233
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,7 +3,7 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.91.0'
6
+ VERSION = '0.92.1'
7
7
 
8
8
  APPMAP_FORMAT_VERSION = '1.9.0'
9
9
 
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.91.0
4
+ version: 0.92.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -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
@@ -453,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
455
  - !ruby/object:Gem::Version
454
456
  version: '0'
455
457
  requirements: []
456
- rubygems_version: 3.0.6
458
+ rubygems_version: 3.1.6
457
459
  signing_key:
458
460
  specification_version: 4
459
461
  summary: Record the operation of a Ruby program, using the AppLand 'AppMap' format.