appmap 0.101.0 → 0.102.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/appmap/cucumber.rb +8 -5
- data/lib/appmap/detect_enabled.rb +50 -31
- data/lib/appmap/minitest.rb +12 -10
- data/lib/appmap/rspec.rb +5 -2
- data/lib/appmap/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1df97ff2f7c62ce830193389327e102a89798678350dbc653aecc98157e502cb
         | 
| 4 | 
            +
              data.tar.gz: ff14a72537014f549a5094b592a6dd28e9a6658679e0c411529d7c4c12491822
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 21781f0d7b9d61d72cd6b442b1105a1eabd19ba07ccca62bb8fd5acaede9e6db2a3cf5594a80c1270ff574d977b709c22031a12a88361cd36fe3013e5238cb03
         | 
| 7 | 
            +
              data.tar.gz: bcc9fd8526da90172d0f7f159a1c4a61a0245e70d1d800f38b98e1d13f0a35ee26898c064107a0de5eb3f7d11d1eecf98c12df1f14a4c37cb72582a1a6bdcf1d
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,10 @@ | |
| 1 | 
            +
            # [0.102.0](https://github.com/getappmap/appmap-ruby/compare/v0.101.0...v0.102.0) (2023-07-18)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            ### Features
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            * Discourage conflicting recording methods ([f86303b](https://github.com/getappmap/appmap-ruby/commit/f86303bf1b62d5131d9ed2c10e01225ec21c1405))
         | 
| 7 | 
            +
             | 
| 1 8 | 
             
            # [0.101.0](https://github.com/getappmap/appmap-ruby/compare/v0.100.0...v0.101.0) (2023-07-17)
         | 
| 2 9 |  | 
| 3 10 |  | 
    
        data/lib/appmap/cucumber.rb
    CHANGED
    
    | @@ -1,13 +1,14 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 3 | 
            +
            require_relative '../appmap'
         | 
| 4 | 
            +
            require_relative './util'
         | 
| 5 | 
            +
            require_relative './detect_enabled'
         | 
| 5 6 | 
             
            require 'fileutils'
         | 
| 6 7 |  | 
| 7 8 | 
             
            module AppMap
         | 
| 8 9 | 
             
              module Cucumber
         | 
| 9 10 | 
             
                APPMAP_OUTPUT_DIR = 'tmp/appmap/cucumber'
         | 
| 10 | 
            -
             | 
| 11 | 
            +
             | 
| 11 12 | 
             
                ScenarioAttributes = Struct.new(:name, :feature, :feature_group)
         | 
| 12 13 |  | 
| 13 14 | 
             
                ProviderStruct = Struct.new(:scenario) do
         | 
| @@ -43,11 +44,13 @@ module AppMap | |
| 43 44 |  | 
| 44 45 | 
             
                class << self
         | 
| 45 46 | 
             
                  def init
         | 
| 47 | 
            +
                    AppMap::DetectEnabled.discourage_conflicting_recording_methods :cucumber
         | 
| 48 | 
            +
             | 
| 46 49 | 
             
                    warn 'Configuring AppMap recorder for Cucumber'
         | 
| 47 50 |  | 
| 48 51 | 
             
                    FileUtils.mkdir_p APPMAP_OUTPUT_DIR
         | 
| 49 52 | 
             
                  end
         | 
| 50 | 
            -
             | 
| 53 | 
            +
             | 
| 51 54 | 
             
                  def write_scenario(scenario, appmap)
         | 
| 52 55 | 
             
                    appmap['metadata'] = update_metadata(scenario, appmap['metadata'])
         | 
| 53 56 | 
             
                    scenario_filename = AppMap::Util.scenario_filename(appmap['metadata']['name'])
         | 
| @@ -62,7 +65,7 @@ module AppMap | |
| 62 65 | 
             
                  def run
         | 
| 63 66 | 
             
                    init
         | 
| 64 67 | 
             
                  end
         | 
| 65 | 
            -
             | 
| 68 | 
            +
             | 
| 66 69 | 
             
                  protected
         | 
| 67 70 |  | 
| 68 71 | 
             
                  def cucumber_version
         | 
| @@ -9,6 +9,32 @@ module AppMap | |
| 9 9 | 
             
                @@detected_for_method = {}
         | 
| 10 10 |  | 
| 11 11 | 
             
                class << self
         | 
| 12 | 
            +
                  def discourage_conflicting_recording_methods(recording_method)
         | 
| 13 | 
            +
                    return if ENV['APPMAP_DISCOURAGE_CONFLICTING_RECORDING_METHODS'] == 'false'
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    return unless enabled?(recording_method.to_sym) && enabled?(:requests)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    warn Util.color <<~MSG, :yellow
         | 
| 18 | 
            +
            AppMap recording is enabled for both 'requests' and '#{recording_method}'. This is not recommended
         | 
| 19 | 
            +
            because the recordings will contain duplicitive information, and in some case may conflict with each other.
         | 
| 20 | 
            +
                    MSG
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    return unless ENV['APPMAP'] == 'true'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    warn Util.color <<~MSG, :yellow
         | 
| 25 | 
            +
            The environment contains APPMAP=true, which is not recommended in this application environment because
         | 
| 26 | 
            +
            it enables all recording methods. Consider letting AppMap detect the appropriate recording method,
         | 
| 27 | 
            +
            or explicitly enabling only the recording methods you want to use using environment variables like
         | 
| 28 | 
            +
            APPMAP_RECORD_REQUESTS, APPMAP_RECORD_RSPEC, etc.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            See https://appmap.io/docs/reference/appmap-ruby.html#advanced-runtime-options for more information.
         | 
| 31 | 
            +
                    MSG
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def enabled?(recording_method)
         | 
| 35 | 
            +
                    new(recording_method).enabled?
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 12 38 | 
             
                  def clear_cache
         | 
| 13 39 | 
             
                    @@detected_for_method = {}
         | 
| 14 40 | 
             
                  end
         | 
| @@ -19,20 +45,20 @@ module AppMap | |
| 19 45 | 
             
                end
         | 
| 20 46 |  | 
| 21 47 | 
             
                def enabled?
         | 
| 22 | 
            -
                  unless @@detected_for_method[@recording_method].nil?
         | 
| 23 | 
            -
                    return @@detected_for_method[@recording_method]
         | 
| 24 | 
            -
                  end
         | 
| 48 | 
            +
                  return @@detected_for_method[@recording_method] unless @@detected_for_method[@recording_method].nil?
         | 
| 25 49 |  | 
| 26 | 
            -
                   | 
| 50 | 
            +
                  if @recording_method && !AppMap::RECORDING_METHODS.member?(@recording_method)
         | 
| 51 | 
            +
                    raise "Unrecognized recording method: #{@recording_method}"
         | 
| 52 | 
            +
                  end
         | 
| 27 53 |  | 
| 28 54 | 
             
                  message, enabled, enabled_by_env = detect_enabled
         | 
| 29 55 |  | 
| 30 56 | 
             
                  @@detected_for_method[@recording_method] = enabled
         | 
| 31 57 |  | 
| 32 | 
            -
                  if @recording_method
         | 
| 33 | 
            -
                     | 
| 34 | 
            -
                       | 
| 35 | 
            -
                     | 
| 58 | 
            +
                  if @recording_method && (enabled && enabled_by_app_env?)
         | 
| 59 | 
            +
                    warn AppMap::Util.color(
         | 
| 60 | 
            +
                      "AppMap #{@recording_method.nil? ? '' : "#{@recording_method} "}recording is enabled because #{message}", :magenta
         | 
| 61 | 
            +
                    )
         | 
| 36 62 | 
             
                  end
         | 
| 37 63 |  | 
| 38 64 | 
             
                  enabled
         | 
| @@ -49,48 +75,41 @@ module AppMap | |
| 49 75 | 
             
                  ]
         | 
| 50 76 |  | 
| 51 77 | 
             
                  message, enabled = []
         | 
| 52 | 
            -
                  while enabled.nil? && !detection_functions.empty?
         | 
| 53 | 
            -
                    message, enabled = method(detection_functions.shift).call
         | 
| 54 | 
            -
                  end
         | 
| 78 | 
            +
                  message, enabled = method(detection_functions.shift).call while enabled.nil? && !detection_functions.empty?
         | 
| 55 79 |  | 
| 56 | 
            -
                   | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
                   | 
| 60 | 
            -
                    return [ 'it is not enabled by any configuration or framework', false, false ]
         | 
| 61 | 
            -
                  end
         | 
| 80 | 
            +
                  return [ 'it is not enabled by any configuration or framework', false, false ] if enabled.nil?
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  _, enabled_by_env = enabled_by_app_env?
         | 
| 83 | 
            +
                  [ message, enabled, enabled_by_env ]
         | 
| 62 84 | 
             
                end
         | 
| 63 85 |  | 
| 64 86 | 
             
                def enabled_by_testing?
         | 
| 65 | 
            -
                   | 
| 66 | 
            -
             | 
| 67 | 
            -
                   | 
| 87 | 
            +
                  return unless %i[rspec minitest cucumber].member?(@recording_method)
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  [ "running tests with #{@recording_method}", true ]
         | 
| 68 90 | 
             
                end
         | 
| 69 91 |  | 
| 70 92 | 
             
                def enabled_by_app_env?
         | 
| 71 93 | 
             
                  env_name, app_env = detect_app_env
         | 
| 72 | 
            -
                  if @recording_method.nil?
         | 
| 73 | 
            -
                    return [ "#{env_name} is '#{app_env}'", true ] if %w[test development].member?(app_env)
         | 
| 74 | 
            -
                  end
         | 
| 94 | 
            +
                  return [ "#{env_name} is '#{app_env}'", true ] if @recording_method.nil? && %w[test development].member?(app_env)
         | 
| 75 95 |  | 
| 76 | 
            -
                   | 
| 77 | 
            -
             | 
| 78 | 
            -
                  end
         | 
| 96 | 
            +
                  return unless %i[remote requests].member?(@recording_method)
         | 
| 97 | 
            +
                  return [ "#{env_name} is '#{app_env}'", true ] if app_env == 'development'
         | 
| 79 98 | 
             
                end
         | 
| 80 99 |  | 
| 81 100 | 
             
                def detect_app_env
         | 
| 82 101 | 
             
                  if rails_env
         | 
| 83 | 
            -
                     | 
| 102 | 
            +
                    [ 'RAILS_ENV', rails_env ]
         | 
| 84 103 | 
             
                  elsif ENV['APP_ENV']
         | 
| 85 | 
            -
                     | 
| 104 | 
            +
                    [ 'APP_ENV', ENV['APP_ENV']]
         | 
| 86 105 | 
             
                  end
         | 
| 87 106 | 
             
                end
         | 
| 88 107 |  | 
| 89 108 | 
             
                def globally_enabled?
         | 
| 90 109 | 
             
                  # Don't auto-enable request recording in the 'test' environment, because users probably don't want
         | 
| 91 110 | 
             
                  # AppMaps of both test cases and requests. Requests recording can always be enabled by APPMAP_RECORD_REQUESTS=true.
         | 
| 92 | 
            -
                  requests_recording_in_test = ->  | 
| 93 | 
            -
                  [ 'APPMAP=true', true ] if ENV['APPMAP'] == 'true' && !requests_recording_in_test. | 
| 111 | 
            +
                  requests_recording_in_test = -> { [ :requests ].member?(@recording_method) && detect_app_env == 'test' }
         | 
| 112 | 
            +
                  [ 'APPMAP=true', true ] if ENV['APPMAP'] == 'true' && !requests_recording_in_test.call
         | 
| 94 113 | 
             
                end
         | 
| 95 114 |  | 
| 96 115 | 
             
                def globally_disabled?
         | 
| @@ -114,7 +133,7 @@ module AppMap | |
| 114 133 | 
             
                def rails_env
         | 
| 115 134 | 
             
                  return Rails.env if defined?(::Rails::Railtie)
         | 
| 116 135 |  | 
| 117 | 
            -
                   | 
| 136 | 
            +
                  ENV.fetch('RAILS_ENV', nil)
         | 
| 118 137 | 
             
                end
         | 
| 119 138 | 
             
              end
         | 
| 120 139 | 
             
            end
         | 
    
        data/lib/appmap/minitest.rb
    CHANGED
    
    | @@ -1,7 +1,8 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 3 | 
            +
            require_relative '../appmap'
         | 
| 4 | 
            +
            require_relative './util'
         | 
| 5 | 
            +
            require_relative './detect_enabled'
         | 
| 5 6 | 
             
            require 'fileutils'
         | 
| 6 7 | 
             
            require 'active_support'
         | 
| 7 8 | 
             
            require 'active_support/core_ext'
         | 
| @@ -32,7 +33,9 @@ module AppMap | |
| 32 33 |  | 
| 33 34 | 
             
                  def finish(failures, exception)
         | 
| 34 35 | 
             
                    failed = failures.any? || exception
         | 
| 35 | 
            -
                     | 
| 36 | 
            +
                    if AppMap::Minitest::LOG
         | 
| 37 | 
            +
                      warn "Finishing recording of #{failed ? 'failed ' : ''} test #{test.class}.#{test.name}"
         | 
| 38 | 
            +
                    end
         | 
| 36 39 | 
             
                    warn "Exception: #{exception}" if exception && AppMap::Minitest::LOG
         | 
| 37 40 |  | 
| 38 41 | 
             
                    if failed
         | 
| @@ -78,7 +81,8 @@ module AppMap | |
| 78 81 | 
             
                  end
         | 
| 79 82 |  | 
| 80 83 | 
             
                  def begin_test(test, name)
         | 
| 81 | 
            -
                    AppMap. | 
| 84 | 
            +
                    AppMap::DetectEnabled.discourage_conflicting_recording_methods :minitest if first_recording?
         | 
| 85 | 
            +
             | 
| 82 86 | 
             
                    @recording_count += 1
         | 
| 83 87 |  | 
| 84 88 | 
             
                    @recordings_by_test[test.object_id] = Recording.new(test, name)
         | 
| @@ -107,24 +111,22 @@ module AppMap | |
| 107 111 | 
             
                      m[:frameworks] ||= []
         | 
| 108 112 | 
             
                      m[:frameworks] << {
         | 
| 109 113 | 
             
                        name: 'minitest',
         | 
| 110 | 
            -
                        version: Gem.loaded_specs['minitest']&.version&.to_s | 
| 114 | 
            +
                        version: Gem.loaded_specs['minitest']&.version&.to_s
         | 
| 111 115 | 
             
                      }
         | 
| 112 116 | 
             
                      m[:recorder] = {
         | 
| 113 117 | 
             
                        name: 'minitest',
         | 
| 114 | 
            -
                        type: 'tests' | 
| 118 | 
            +
                        type: 'tests'
         | 
| 115 119 | 
             
                      }
         | 
| 116 120 | 
             
                      m[:test_status] = test_status
         | 
| 117 121 | 
             
                      m[:test_failure] = test_failure if test_failure
         | 
| 118 | 
            -
                      if exception
         | 
| 119 | 
            -
                        m[:exception] = Util.format_exception(exception)
         | 
| 120 | 
            -
                      end
         | 
| 122 | 
            +
                      m[:exception] = Util.format_exception(exception) if exception
         | 
| 121 123 | 
             
                    end
         | 
| 122 124 |  | 
| 123 125 | 
             
                    appmap = {
         | 
| 124 126 | 
             
                      version: AppMap::APPMAP_FORMAT_VERSION,
         | 
| 125 127 | 
             
                      metadata: metadata,
         | 
| 126 128 | 
             
                      classMap: class_map,
         | 
| 127 | 
            -
                      events: events | 
| 129 | 
            +
                      events: events
         | 
| 128 130 | 
             
                    }.compact
         | 
| 129 131 | 
             
                    fname = AppMap::Util.scenario_filename(name)
         | 
| 130 132 |  | 
    
        data/lib/appmap/rspec.rb
    CHANGED
    
    | @@ -1,7 +1,8 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 3 | 
            +
            require_relative '../appmap'
         | 
| 4 | 
            +
            require_relative './util'
         | 
| 5 | 
            +
            require_relative './detect_enabled'
         | 
| 5 6 | 
             
            require 'set'
         | 
| 6 7 | 
             
            require 'fileutils'
         | 
| 7 8 |  | 
| @@ -161,6 +162,8 @@ module AppMap | |
| 161 162 | 
             
                  end
         | 
| 162 163 |  | 
| 163 164 | 
             
                  def begin_spec(example)
         | 
| 165 | 
            +
                    AppMap::DetectEnabled.discourage_conflicting_recording_methods :rspec if first_recording?
         | 
| 166 | 
            +
             | 
| 164 167 | 
             
                    @recording_count += 1
         | 
| 165 168 | 
             
                    # Disable RSpec recording for RSwag, because all the action happens in the before block.
         | 
| 166 169 | 
             
                    # The example is empty except for assertions. So RSwag has its own recorder, and RSpec
         | 
    
        data/lib/appmap/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 0.102.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Kevin Gilpin
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-07- | 
| 11 | 
            +
            date: 2023-07-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: method_source
         |