appmap 0.51.2 → 0.54.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/.travis.yml +3 -1
- data/CHANGELOG.md +40 -0
- data/Rakefile +21 -5
- data/appmap.gemspec +8 -7
- data/exe/appmap-agent-init +19 -0
- data/exe/appmap-inspect +7 -0
- data/lib/appmap.rb +29 -119
- data/lib/appmap/agent.rb +115 -0
- data/lib/appmap/class_map.rb +2 -2
- data/lib/appmap/command/agent_setup/init.rb +44 -0
- data/lib/appmap/command/inspect.rb +27 -0
- data/lib/appmap/command_error.rb +13 -0
- data/lib/appmap/config.rb +13 -4
- data/lib/appmap/handler/net_http.rb +2 -1
- data/lib/appmap/handler/rails/request_handler.rb +2 -1
- data/lib/appmap/metadata.rb +4 -2
- data/lib/appmap/minitest.rb +2 -0
- data/lib/appmap/node_cli.rb +59 -0
- data/lib/appmap/railtie.rb +2 -2
- data/lib/appmap/rspec.rb +5 -3
- data/lib/appmap/service/guesser.rb +2 -9
- data/lib/appmap/swagger.rb +2 -0
- data/lib/appmap/swagger/configuration.rb +70 -0
- data/lib/appmap/swagger/markdown_descriptions.rb +43 -0
- data/lib/appmap/swagger/rake_tasks.rb +43 -0
- data/lib/appmap/swagger/stable.rb +37 -0
- data/lib/appmap/util.rb +31 -2
- data/lib/appmap/version.rb +1 -1
- data/package.json +5 -7
- data/spec/config_spec.rb +0 -1
- data/spec/fixtures/hook/.gitignore +2 -0
- data/spec/fixtures/hook/app/controllers/api/api_keys_controller.rb +1 -0
- data/spec/fixtures/hook/app/controllers/organizations_controller.rb +1 -0
- data/spec/fixtures/hook/app/models/api_key.rb +1 -0
- data/spec/fixtures/hook/app/models/configuration.rb +1 -0
- data/spec/fixtures/hook/app/models/show.rb +1 -0
- data/spec/fixtures/hook/app/models/user.rb +1 -0
- data/spec/fixtures/hook/revoke_api_key.appmap.json +847 -0
- data/spec/fixtures/hook/spec/api_spec.rb +1 -0
- data/spec/fixtures/hook/spec/user_spec.rb +1 -0
- data/spec/fixtures/hook/user_page_scenario.appmap.json +1722 -0
- data/spec/fixtures/rails5_users_app/config/environments/test.rb +3 -0
- data/spec/fixtures/rails5_users_app/docker-compose.yml +1 -1
- data/spec/fixtures/rails6_users_app/Dockerfile +9 -1
- data/spec/fixtures/rails6_users_app/appmap.yml +3 -1
- data/spec/fixtures/rails6_users_app/config/environments/test.rb +3 -0
- data/spec/fixtures/rails6_users_app/docker-compose.yml +1 -1
- data/spec/fixtures/rails6_users_app/lib/tasks/appmap.rake +13 -0
- data/spec/{abstract_controller_base_spec.rb → rails_recording_spec.rb} +2 -21
- data/spec/rails_spec_helper.rb +22 -0
- data/spec/swagger/swagger_spec.rb +47 -0
- data/test/{cli_test.rb → agent_setup_init_test.rb} +4 -4
- data/test/fixtures/gem_test/Gemfile +1 -0
- data/test/gem_test.rb +1 -0
- data/test/inspect_cli_test.rb +12 -0
- data/yarn.lock +477 -0
- metadata +39 -63
- data/exe/appmap-agent-setup +0 -47
- data/lib/appmap/algorithm/prune_class_map.rb +0 -67
- data/lib/appmap/algorithm/stats.rb +0 -91
- data/lib/appmap/command/init.rb +0 -42
- data/lib/appmap/command/record.rb +0 -38
- data/lib/appmap/command/stats.rb +0 -14
- data/lore/pages/2019-05-21-install-and-record/index.pug +0 -51
- data/lore/pages/2019-05-21-install-and-record/install_example_appmap.png +0 -0
- data/lore/pages/2019-05-21-install-and-record/metadata.yml +0 -5
- data/lore/pages/layout.pug +0 -66
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.css +0 -1912
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.css.map +0 -1
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.min.css +0 -7
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-grid.min.css.map +0 -1
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.css +0 -331
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.css.map +0 -1
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.min.css +0 -8
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap-reboot.min.css.map +0 -1
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.css +0 -9030
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.css.map +0 -1
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.min.css +0 -7
- data/lore/public/lib/bootstrap-4.1.3/css/bootstrap.min.css.map +0 -1
- data/lore/public/stylesheets/style.css +0 -8
- data/package-lock.json +0 -1064
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a00ec7ef6ec83aebf28d11c8004c89885ae32562ef6384c6c7880ca09d380027
|
4
|
+
data.tar.gz: a16129c01467f043eb18786ea8f3cae2df65226b924e6f85b40614f7d563e8a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daeec49a1a7e46fa5d5f572755725d766a2c37e00f8013d93ac1cde6d7dcff504633b4ca74cbbc94c9a3d355bc221d795970e0af393be29557f03d8fbe06114a
|
7
|
+
data.tar.gz: f1c8b85f2e9224604f3138c208dbcff0dbb939aa1038834a8ca761b290b5f07086023857881dd4c14c37644a9ae403108ba059c4a337796ea7ecab0e6b2826bb
|
data/.travis.yml
CHANGED
@@ -26,7 +26,9 @@ before_install:
|
|
26
26
|
if [ ! -z "$DOCKERHUB_PASSWORD" ] && [ ! -z "$DOCKERHUB_USERNAME" ]; then
|
27
27
|
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin ;
|
28
28
|
fi
|
29
|
-
|
29
|
+
- |
|
30
|
+
nvm install --lts \
|
31
|
+
&& nvm use --lts
|
30
32
|
|
31
33
|
# GEM_ALTERNATIVE_NAME only needed for deployment
|
32
34
|
jobs:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
# [0.54.0](https://github.com/applandinc/appmap-ruby/compare/v0.53.0...v0.54.0) (2021-06-24)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Handle new behavior in RSpec ExampleGroup ([176d0df](https://github.com/applandinc/appmap-ruby/commit/176d0dfca0b2e4cc5a8908fa67c01dd0c79ef175))
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* Add swagger rake task ([0aaae49](https://github.com/applandinc/appmap-ruby/commit/0aaae4973f0df530c75ed92b93f8a1940a948091))
|
12
|
+
|
13
|
+
# [0.53.0](https://github.com/applandinc/appmap-ruby/compare/v0.52.1...v0.53.0) (2021-06-23)
|
14
|
+
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* appmap-agent-setup as a separate command not using GLI library ([f0eedb7](https://github.com/applandinc/appmap-ruby/commit/f0eedb7451368ea0399872f3be680e1581ac6200))
|
19
|
+
|
20
|
+
## [0.52.1](https://github.com/applandinc/appmap-ruby/compare/v0.52.0...v0.52.1) (2021-06-23)
|
21
|
+
|
22
|
+
|
23
|
+
### Bug Fixes
|
24
|
+
|
25
|
+
* Better project name guesser ([d22f379](https://github.com/applandinc/appmap-ruby/commit/d22f379623bd3022ba34d7241838fe6abbbb61d6))
|
26
|
+
|
27
|
+
# [0.52.0](https://github.com/applandinc/appmap-ruby/compare/v0.51.3...v0.52.0) (2021-06-22)
|
28
|
+
|
29
|
+
|
30
|
+
### Features
|
31
|
+
|
32
|
+
* Bundle NPM package @appland/cli with this gem ([945e28c](https://github.com/applandinc/appmap-ruby/commit/945e28c699fff6bd97ae51983816e97955c4ff36))
|
33
|
+
|
34
|
+
## [0.51.3](https://github.com/applandinc/appmap-ruby/compare/v0.51.2...v0.51.3) (2021-06-22)
|
35
|
+
|
36
|
+
|
37
|
+
### Bug Fixes
|
38
|
+
|
39
|
+
* Remove outdate lore, command, and algorithm code ([d899989](https://github.com/applandinc/appmap-ruby/commit/d8999896c611c16f51a092f5f7afb3d7203d7e72))
|
40
|
+
|
1
41
|
## [0.51.2](https://github.com/applandinc/appmap-ruby/compare/v0.51.1...v0.51.2) (2021-06-22)
|
2
42
|
|
3
43
|
|
data/Rakefile
CHANGED
@@ -16,6 +16,22 @@ end
|
|
16
16
|
|
17
17
|
namespace 'gem' do
|
18
18
|
require 'bundler/gem_tasks'
|
19
|
+
|
20
|
+
module Bundler
|
21
|
+
class GemHelper
|
22
|
+
alias default_build_gem build_gem
|
23
|
+
|
24
|
+
# A handy tip - find the location of any Rake task using `rake -W`.
|
25
|
+
# rake -W build
|
26
|
+
# ~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/gem_helper.rb:39:in `install'
|
27
|
+
def build_gem
|
28
|
+
# Ensure that NPM packages are installed before building.
|
29
|
+
sh('yarn install --prod'.shellsplit)
|
30
|
+
|
31
|
+
default_build_gem
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
19
35
|
end
|
20
36
|
|
21
37
|
RUBY_VERSIONS=%w[2.5 2.6 2.7]
|
@@ -34,18 +50,19 @@ def run_cmd(*cmd)
|
|
34
50
|
raise 'Docker build failed'
|
35
51
|
end
|
36
52
|
end
|
37
|
-
|
53
|
+
|
38
54
|
def build_base_image(ruby_version)
|
39
55
|
run_cmd "docker build" \
|
40
56
|
" --build-arg RUBY_VERSION=#{ruby_version}" \
|
41
57
|
" --build-arg GEM_VERSION=#{GEM_VERSION}" \
|
42
58
|
" -t appmap:#{GEM_VERSION} -f Dockerfile.appmap ."
|
43
59
|
end
|
44
|
-
|
60
|
+
|
45
61
|
def build_app_image(app, ruby_version)
|
46
62
|
Dir.chdir "spec/fixtures/#{app}" do
|
47
|
-
|
48
|
-
|
63
|
+
env = {"RUBY_VERSION" => ruby_version, "GEM_VERSION" => GEM_VERSION}
|
64
|
+
run_cmd(env,
|
65
|
+
"docker-compose build" \
|
49
66
|
" --build-arg RUBY_VERSION=#{ruby_version}" \
|
50
67
|
" --build-arg GEM_VERSION=#{GEM_VERSION}" )
|
51
68
|
end
|
@@ -139,4 +156,3 @@ task spec: %i[spec:all]
|
|
139
156
|
task test: %i[spec:all minitest]
|
140
157
|
|
141
158
|
task default: :test
|
142
|
-
|
data/appmap.gemspec
CHANGED
@@ -4,8 +4,6 @@ lib = File.expand_path('lib', __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'appmap/version'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
Gem::Specification.new do |spec|
|
10
8
|
# ability to parameterize gem name is added intentionally,
|
11
9
|
# to support the possibility of unofficial releases, e.g. during CI tests
|
@@ -25,19 +23,22 @@ Gem::Specification.new do |spec|
|
|
25
23
|
spec.bindir = 'exe'
|
26
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
25
|
|
28
|
-
|
26
|
+
strip_dir = ->(file) { file.index(Dir.pwd) == 0 ? file[Dir.pwd.length+1...file.length] : file }
|
27
|
+
Dir.glob(File.join(__dir__, 'node_modules/**/*')).map(&strip_dir).each do |filename|
|
28
|
+
next if File.directory?(filename) || filename.length > 100
|
29
|
+
spec.files << filename
|
30
|
+
end
|
29
31
|
|
32
|
+
spec.extensions << "ext/appmap/extconf.rb"
|
30
33
|
spec.require_paths = ['lib']
|
31
34
|
|
32
35
|
spec.add_dependency 'activesupport'
|
33
|
-
spec.add_dependency 'faraday'
|
34
|
-
spec.add_dependency 'gli'
|
35
36
|
spec.add_dependency 'method_source'
|
36
|
-
spec.add_dependency 'parser'
|
37
37
|
spec.add_dependency 'rack'
|
38
|
+
spec.add_dependency 'reverse_markdown'
|
38
39
|
|
39
40
|
spec.add_development_dependency 'bundler', '>= 1.16'
|
40
|
-
spec.add_development_dependency 'minitest', '
|
41
|
+
spec.add_development_dependency 'minitest', '= 5.14.4'
|
41
42
|
spec.add_development_dependency 'pry-byebug'
|
42
43
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
43
44
|
spec.add_development_dependency 'rdoc'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'appmap'
|
6
|
+
require 'appmap/command/agent_setup/init'
|
7
|
+
|
8
|
+
@options = {:config_file => AppMap::DEFAULT_CONFIG_FILE_PATH}
|
9
|
+
|
10
|
+
OptionParser.new do |parser|
|
11
|
+
parser.banner = 'Usage: bundle exec exe/appmap-agent-init [options]'
|
12
|
+
|
13
|
+
description = "AppMap configuration file path (default: #{AppMap::DEFAULT_CONFIG_FILE_PATH})"
|
14
|
+
parser.on('-c', '--config=FILEPATH', description) do |filepath|
|
15
|
+
@options[:config_file] = filepath
|
16
|
+
end
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
AppMap::Command::AgentSetup::Init.new(@options[:config_file]).perform
|
data/exe/appmap-inspect
ADDED
data/lib/appmap.rb
CHANGED
@@ -1,124 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# This is the file that's loaded when you require 'appmap'.
|
4
|
+
# If you require this file, we assume that you want to automatically activate all
|
5
|
+
# the AppMap functionality that seems suitable for your project.
|
6
|
+
# For example, if your project is a Rails project, the Railtie will be loaded.
|
7
|
+
# If your bundle includes rspec, the appmap/rspec will be loaded.
|
8
|
+
#
|
9
|
+
# If you don't want this "all-in" behavior, then you can use the 'require' option
|
10
|
+
# in your Gemfile to selectively activate just the AppMap features that you want. Then
|
11
|
+
# you can manually configure/require other features, elsewhere in your code.
|
12
|
+
# Note that you should always require 'appmap/agent' as early as possible, so that it can
|
13
|
+
# observe and hook as much code loading as possible.
|
14
|
+
#
|
15
|
+
# Modules that you can load independently include:
|
16
|
+
# - appmap/agent
|
17
|
+
# - appmap/railtie
|
18
|
+
# - appmap/rspec
|
19
|
+
# - appmap/minitest
|
20
|
+
# - appmap/swagger (Rake task)
|
9
21
|
|
10
22
|
require 'appmap/version'
|
11
|
-
require 'appmap/
|
12
|
-
require 'appmap/config'
|
13
|
-
require 'appmap/trace'
|
14
|
-
require 'appmap/class_map'
|
15
|
-
require 'appmap/metadata'
|
16
|
-
require 'appmap/util'
|
17
|
-
require 'appmap/open'
|
18
|
-
|
19
|
-
# load extension
|
20
|
-
require 'appmap/appmap'
|
21
|
-
|
22
|
-
module AppMap
|
23
|
-
class << self
|
24
|
-
@configuration = nil
|
25
|
-
@configuration_file_path = nil
|
26
|
-
|
27
|
-
# Gets the configuration. If there is no configuration, the default
|
28
|
-
# configuration is initialized.
|
29
|
-
def configuration
|
30
|
-
@configuration ||= initialize_configuration
|
31
|
-
end
|
32
|
-
|
33
|
-
# Sets the configuration. This is only expected to happen once per
|
34
|
-
# Ruby process.
|
35
|
-
def configuration=(config)
|
36
|
-
warn 'AppMap is already configured' if @configuration && config
|
37
|
-
|
38
|
-
@configuration = config
|
39
|
-
end
|
40
|
-
|
41
|
-
def default_config_file_path
|
42
|
-
ENV['APPMAP_CONFIG_FILE'] || 'appmap.yml'
|
43
|
-
end
|
44
|
-
|
45
|
-
# Configures AppMap for recording. Default behavior is to configure from
|
46
|
-
# APPMAP_CONFIG_FILE, or 'appmap.yml'. If no config file is available, a
|
47
|
-
# configuration will be automatically generated and used - and the user is prompted
|
48
|
-
# to create the config file.
|
49
|
-
#
|
50
|
-
# This method also activates the code hooks which record function calls as trace events.
|
51
|
-
# Call this function before the program code is loaded by the Ruby VM, otherwise
|
52
|
-
# the load events won't be seen and the hooks won't activate.
|
53
|
-
def initialize_configuration(config_file_path = default_config_file_path)
|
54
|
-
startup_message "Configuring AppMap from path #{config_file_path}"
|
55
|
-
Config.load_from_file(config_file_path).tap do |configuration|
|
56
|
-
self.configuration = configuration
|
57
|
-
Hook.new(configuration).enable
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def info(msg)
|
62
|
-
if defined?(::Rails) && defined?(::Rails.logger)
|
63
|
-
::Rails.logger.info msg
|
64
|
-
else
|
65
|
-
warn msg
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Used to start tracing, stop tracing, and record events.
|
70
|
-
def tracing
|
71
|
-
@tracing ||= Trace::Tracing.new
|
72
|
-
end
|
73
|
-
|
74
|
-
# Records the events which occur while processing a block,
|
75
|
-
# and returns an AppMap as a Hash.
|
76
|
-
def record
|
77
|
-
tracer = tracing.trace
|
78
|
-
begin
|
79
|
-
yield
|
80
|
-
ensure
|
81
|
-
tracing.delete(tracer)
|
82
|
-
end
|
83
|
-
|
84
|
-
events = [].tap do |event_list|
|
85
|
-
event_list << tracer.next_event.to_h while tracer.event?
|
86
|
-
end
|
87
|
-
{
|
88
|
-
'version' => AppMap::APPMAP_FORMAT_VERSION,
|
89
|
-
'metadata' => detect_metadata,
|
90
|
-
'classMap' => class_map(tracer.event_methods),
|
91
|
-
'events' => events
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
# Uploads an AppMap to the AppLand website and displays it.
|
96
|
-
def open(appmap = nil, &block)
|
97
|
-
appmap ||= AppMap.record(&block)
|
98
|
-
AppMap::Open.new(appmap).perform
|
99
|
-
end
|
100
|
-
|
101
|
-
# Builds a class map from a config and a list of Ruby methods.
|
102
|
-
def class_map(methods)
|
103
|
-
ClassMap.build_from_methods(methods)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Returns default metadata detected from the Ruby system and from the
|
107
|
-
# filesystem.
|
108
|
-
def detect_metadata
|
109
|
-
@metadata ||= Metadata.detect.freeze
|
110
|
-
@metadata.deep_dup
|
111
|
-
end
|
112
|
-
|
113
|
-
def startup_message(msg)
|
114
|
-
if defined?(::Rails) && defined?(::Rails.logger) && ::Rails.logger
|
115
|
-
::Rails.logger.debug msg
|
116
|
-
elsif ENV['DEBUG'] == 'true'
|
117
|
-
warn msg
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
23
|
+
require 'appmap/agent'
|
122
24
|
|
123
25
|
lambda do
|
124
26
|
Initializer = Struct.new(:class_name, :module_name, :gem_module_name)
|
@@ -126,7 +28,10 @@ lambda do
|
|
126
28
|
INITIALIZERS = {
|
127
29
|
'Rails::Railtie' => Initializer.new('AppMap::Railtie', 'appmap/railtie', 'railtie'),
|
128
30
|
'RSpec' => Initializer.new('AppMap::RSpec', 'appmap/rspec', 'rspec-core'),
|
129
|
-
'Minitest::Unit::TestCase' => Initializer.new('AppMap::Minitest', 'appmap/minitest', 'minitest')
|
31
|
+
'Minitest::Unit::TestCase' => Initializer.new('AppMap::Minitest', 'appmap/minitest', 'minitest'),
|
32
|
+
'Rake' => [
|
33
|
+
Initializer.new('AppMap::Swagger', 'appmap/swagger', 'rake')
|
34
|
+
]
|
130
35
|
}
|
131
36
|
|
132
37
|
TracePoint.new(:class) do |tp|
|
@@ -138,7 +43,7 @@ lambda do
|
|
138
43
|
|
139
44
|
gem_module_name = initializers.first.gem_module_name
|
140
45
|
|
141
|
-
AppMap.startup_message AppMap::Util.color(<<~LOAD_MSG, :magenta)
|
46
|
+
AppMap::Util.startup_message AppMap::Util.color(<<~LOAD_MSG, :magenta)
|
142
47
|
When 'appmap' was loaded, '#{gem_module_name}' had not been loaded yet. Now '#{gem_module_name}' has
|
143
48
|
just been loaded, so the following AppMap modules will be automatically required:
|
144
49
|
|
@@ -163,6 +68,11 @@ lambda do
|
|
163
68
|
if defined?(::Minitest)
|
164
69
|
require 'appmap/minitest'
|
165
70
|
end
|
71
|
+
|
72
|
+
if defined?(::Rake)
|
73
|
+
require 'appmap/swagger'
|
74
|
+
end
|
75
|
+
|
166
76
|
end.call
|
167
77
|
|
168
78
|
AppMap.initialize_configuration if ENV['APPMAP'] == 'true'
|
data/lib/appmap/agent.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
require_relative 'hook'
|
3
|
+
require_relative 'config'
|
4
|
+
require_relative 'trace'
|
5
|
+
require_relative 'class_map'
|
6
|
+
require_relative 'metadata'
|
7
|
+
require_relative 'util'
|
8
|
+
require_relative 'open'
|
9
|
+
|
10
|
+
# load extension
|
11
|
+
require_relative 'appmap'
|
12
|
+
|
13
|
+
module AppMap
|
14
|
+
class << self
|
15
|
+
@configuration = nil
|
16
|
+
@configuration_file_path = nil
|
17
|
+
|
18
|
+
# Gets the configuration. If there is no configuration, the default
|
19
|
+
# configuration is initialized.
|
20
|
+
def configuration
|
21
|
+
@configuration ||= initialize_configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sets the configuration. This is only expected to happen once per
|
25
|
+
# Ruby process.
|
26
|
+
def configuration=(config)
|
27
|
+
warn 'AppMap is already configured' if @configuration && config
|
28
|
+
|
29
|
+
@configuration = config
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_config_file_path
|
33
|
+
ENV['APPMAP_CONFIG_FILE'] || 'appmap.yml'
|
34
|
+
end
|
35
|
+
|
36
|
+
# Configures AppMap for recording. Default behavior is to configure from
|
37
|
+
# APPMAP_CONFIG_FILE, or 'appmap.yml'. If no config file is available, a
|
38
|
+
# configuration will be automatically generated and used - and the user is prompted
|
39
|
+
# to create the config file.
|
40
|
+
#
|
41
|
+
# This method also activates the code hooks which record function calls as trace events.
|
42
|
+
# Call this function before the program code is loaded by the Ruby VM, otherwise
|
43
|
+
# the load events won't be seen and the hooks won't activate.
|
44
|
+
def initialize_configuration(config_file_path = default_config_file_path)
|
45
|
+
Util.startup_message "Configuring AppMap from path #{config_file_path}"
|
46
|
+
Config.load_from_file(config_file_path).tap do |configuration|
|
47
|
+
self.configuration = configuration
|
48
|
+
Hook.new(configuration).enable
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def info(msg)
|
53
|
+
if defined?(::Rails) && defined?(::Rails.logger)
|
54
|
+
::Rails.logger.info msg
|
55
|
+
else
|
56
|
+
warn msg
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def config_message(msg)
|
61
|
+
logger = if defined?(::Rails) && ::Rails.logger
|
62
|
+
::Rails.logger
|
63
|
+
elsif ENV['DEBUG'] == 'true'
|
64
|
+
method(:warn)
|
65
|
+
else
|
66
|
+
->(msg) { }
|
67
|
+
end
|
68
|
+
logger.call(msg)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Used to start tracing, stop tracing, and record events.
|
72
|
+
def tracing
|
73
|
+
@tracing ||= Trace::Tracing.new
|
74
|
+
end
|
75
|
+
|
76
|
+
# Records the events which occur while processing a block,
|
77
|
+
# and returns an AppMap as a Hash.
|
78
|
+
def record
|
79
|
+
tracer = tracing.trace
|
80
|
+
begin
|
81
|
+
yield
|
82
|
+
ensure
|
83
|
+
tracing.delete(tracer)
|
84
|
+
end
|
85
|
+
|
86
|
+
events = [].tap do |event_list|
|
87
|
+
event_list << tracer.next_event.to_h while tracer.event?
|
88
|
+
end
|
89
|
+
{
|
90
|
+
'version' => AppMap::APPMAP_FORMAT_VERSION,
|
91
|
+
'metadata' => detect_metadata,
|
92
|
+
'classMap' => class_map(tracer.event_methods),
|
93
|
+
'events' => events
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
# Uploads an AppMap to the AppLand website and displays it.
|
98
|
+
def open(appmap = nil, &block)
|
99
|
+
appmap ||= AppMap.record(&block)
|
100
|
+
AppMap::Open.new(appmap).perform
|
101
|
+
end
|
102
|
+
|
103
|
+
# Builds a class map from a config and a list of Ruby methods.
|
104
|
+
def class_map(methods)
|
105
|
+
ClassMap.build_from_methods(methods)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns default metadata detected from the Ruby system and from the
|
109
|
+
# filesystem.
|
110
|
+
def detect_metadata
|
111
|
+
@metadata ||= Metadata.detect.freeze
|
112
|
+
Util.deep_dup(@metadata)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|