appmap 0.37.2 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.travis.yml +2 -23
  4. data/CHANGELOG.md +23 -0
  5. data/CONTRIBUTING.md +22 -0
  6. data/README.md +102 -54
  7. data/Rakefile +3 -3
  8. data/lib/appmap/class_map.rb +25 -8
  9. data/lib/appmap/config.rb +54 -26
  10. data/lib/appmap/hook.rb +18 -3
  11. data/lib/appmap/hook/method.rb +18 -12
  12. data/lib/appmap/rails/request_handler.rb +17 -3
  13. data/lib/appmap/railtie.rb +1 -5
  14. data/lib/appmap/trace.rb +18 -7
  15. data/lib/appmap/version.rb +2 -2
  16. data/spec/abstract_controller_base_spec.rb +125 -64
  17. data/spec/config_spec.rb +1 -0
  18. data/spec/fixtures/hook/exclude.rb +15 -0
  19. data/spec/fixtures/hook/labels.rb +6 -0
  20. data/spec/fixtures/rails5_users_app/Gemfile +3 -4
  21. data/spec/fixtures/rails5_users_app/app/controllers/users_controller.rb +8 -0
  22. data/spec/fixtures/rails5_users_app/appmap.yml +5 -1
  23. data/spec/fixtures/rails5_users_app/config/application.rb +2 -0
  24. data/spec/fixtures/rails5_users_app/config/routes.rb +1 -1
  25. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_api_spec.rb +1 -1
  26. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +27 -0
  27. data/spec/fixtures/rails6_users_app/Gemfile +3 -4
  28. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +8 -0
  29. data/spec/fixtures/rails6_users_app/appmap.yml +6 -1
  30. data/spec/fixtures/rails6_users_app/config/application.rb +2 -0
  31. data/spec/fixtures/rails6_users_app/config/routes.rb +1 -1
  32. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +1 -1
  33. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +27 -0
  34. data/spec/hook_spec.rb +69 -47
  35. data/spec/rails_spec_helper.rb +2 -2
  36. data/spec/record_sql_rails_pg_spec.rb +1 -1
  37. data/spec/rspec_feature_metadata_spec.rb +1 -1
  38. data/spec/spec_helper.rb +1 -0
  39. metadata +7 -68
  40. data/spec/abstract_controller4_base_spec.rb +0 -66
  41. data/spec/fixtures/rails4_users_app/.gitignore +0 -13
  42. data/spec/fixtures/rails4_users_app/.rbenv-gemsets +0 -2
  43. data/spec/fixtures/rails4_users_app/.ruby-version +0 -1
  44. data/spec/fixtures/rails4_users_app/Dockerfile +0 -30
  45. data/spec/fixtures/rails4_users_app/Dockerfile.pg +0 -3
  46. data/spec/fixtures/rails4_users_app/Gemfile +0 -77
  47. data/spec/fixtures/rails4_users_app/README.rdoc +0 -28
  48. data/spec/fixtures/rails4_users_app/Rakefile +0 -6
  49. data/spec/fixtures/rails4_users_app/app/assets/images/.keep +0 -0
  50. data/spec/fixtures/rails4_users_app/app/assets/javascripts/application.js +0 -16
  51. data/spec/fixtures/rails4_users_app/app/assets/stylesheets/application.css +0 -15
  52. data/spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb +0 -27
  53. data/spec/fixtures/rails4_users_app/app/controllers/application_controller.rb +0 -5
  54. data/spec/fixtures/rails4_users_app/app/controllers/concerns/.keep +0 -0
  55. data/spec/fixtures/rails4_users_app/app/controllers/health_controller.rb +0 -5
  56. data/spec/fixtures/rails4_users_app/app/controllers/users_controller.rb +0 -5
  57. data/spec/fixtures/rails4_users_app/app/helpers/application_helper.rb +0 -2
  58. data/spec/fixtures/rails4_users_app/app/mailers/.keep +0 -0
  59. data/spec/fixtures/rails4_users_app/app/models/.keep +0 -0
  60. data/spec/fixtures/rails4_users_app/app/models/concerns/.keep +0 -0
  61. data/spec/fixtures/rails4_users_app/app/models/user.rb +0 -18
  62. data/spec/fixtures/rails4_users_app/app/views/layouts/application.html.haml +0 -7
  63. data/spec/fixtures/rails4_users_app/app/views/users/index.html.haml +0 -7
  64. data/spec/fixtures/rails4_users_app/appmap.yml +0 -3
  65. data/spec/fixtures/rails4_users_app/bin/rails +0 -9
  66. data/spec/fixtures/rails4_users_app/bin/setup +0 -29
  67. data/spec/fixtures/rails4_users_app/bin/spring +0 -17
  68. data/spec/fixtures/rails4_users_app/config.ru +0 -4
  69. data/spec/fixtures/rails4_users_app/config/application.rb +0 -26
  70. data/spec/fixtures/rails4_users_app/config/boot.rb +0 -3
  71. data/spec/fixtures/rails4_users_app/config/database.yml +0 -18
  72. data/spec/fixtures/rails4_users_app/config/environment.rb +0 -5
  73. data/spec/fixtures/rails4_users_app/config/environments/development.rb +0 -41
  74. data/spec/fixtures/rails4_users_app/config/environments/production.rb +0 -79
  75. data/spec/fixtures/rails4_users_app/config/environments/test.rb +0 -42
  76. data/spec/fixtures/rails4_users_app/config/initializers/assets.rb +0 -11
  77. data/spec/fixtures/rails4_users_app/config/initializers/backtrace_silencers.rb +0 -7
  78. data/spec/fixtures/rails4_users_app/config/initializers/cookies_serializer.rb +0 -3
  79. data/spec/fixtures/rails4_users_app/config/initializers/filter_parameter_logging.rb +0 -4
  80. data/spec/fixtures/rails4_users_app/config/initializers/inflections.rb +0 -16
  81. data/spec/fixtures/rails4_users_app/config/initializers/mime_types.rb +0 -4
  82. data/spec/fixtures/rails4_users_app/config/initializers/session_store.rb +0 -3
  83. data/spec/fixtures/rails4_users_app/config/initializers/to_time_preserves_timezone.rb +0 -10
  84. data/spec/fixtures/rails4_users_app/config/initializers/wrap_parameters.rb +0 -14
  85. data/spec/fixtures/rails4_users_app/config/locales/en.yml +0 -23
  86. data/spec/fixtures/rails4_users_app/config/routes.rb +0 -12
  87. data/spec/fixtures/rails4_users_app/config/secrets.yml +0 -22
  88. data/spec/fixtures/rails4_users_app/create_app +0 -23
  89. data/spec/fixtures/rails4_users_app/db/migrate/20191127112304_create_users.rb +0 -10
  90. data/spec/fixtures/rails4_users_app/db/schema.rb +0 -26
  91. data/spec/fixtures/rails4_users_app/db/seeds.rb +0 -7
  92. data/spec/fixtures/rails4_users_app/docker-compose.yml +0 -26
  93. data/spec/fixtures/rails4_users_app/lib/assets/.keep +0 -0
  94. data/spec/fixtures/rails4_users_app/lib/tasks/.keep +0 -0
  95. data/spec/fixtures/rails4_users_app/log/.keep +0 -0
  96. data/spec/fixtures/rails4_users_app/public/404.html +0 -67
  97. data/spec/fixtures/rails4_users_app/public/422.html +0 -67
  98. data/spec/fixtures/rails4_users_app/public/500.html +0 -66
  99. data/spec/fixtures/rails4_users_app/public/favicon.ico +0 -0
  100. data/spec/fixtures/rails4_users_app/public/robots.txt +0 -5
  101. data/spec/fixtures/rails4_users_app/spec/controllers/users_controller_api_spec.rb +0 -49
  102. data/spec/fixtures/rails4_users_app/spec/rails_helper.rb +0 -95
  103. data/spec/fixtures/rails4_users_app/spec/spec_helper.rb +0 -96
  104. data/spec/fixtures/rails4_users_app/test/fixtures/users.yml +0 -9
  105. data/spec/record_sql_rails4_pg_spec.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0211b21334945f6786d150fdf1a0dea8a062cbc2d59c4b347f72555232ec6480
4
- data.tar.gz: ac2785471ed35210ba1c3801e8a7d186adb99d9b9369c24eb2c9f4d41a352e33
3
+ metadata.gz: d747c0e65dc1efb45769ae9118a7b97015b0378d79e20eec855e74c20b622af2
4
+ data.tar.gz: dcc3b91f32246aaefd02fbcf47672bfdf13acf6cadb715fbc5ff0040dbcfbf72
5
5
  SHA512:
6
- metadata.gz: d5049f8c464b5f6e6afd7567fcfe62d481c70b7db6d473f93a832763e4352c04b6d2cff3d3d03a452f82033f4220cb821f36152c003794c7adba89432a2b513a
7
- data.tar.gz: 631f8ab86e132e45c1b95b667d7789b870eab393293d62c7e1f77daf3cf3f9a5c7174e913fa0bc20ec92a87f88f278bee69f41c6b2c14d166b1745df71321d0b
6
+ metadata.gz: 5f82a6a0cf8075537b0835e783779c827c5afed81e83e242bc97cbfd5b6ef0320fe352235436f57009a63db321223b9f7f82e8bcdced558d9b935a2ce4e4cbf3
7
+ data.tar.gz: aaa4676d24b6bb1bcbd34fb7f0e3a0244d005c36dd89782b774b342b7e30e1c9637795d0d492522b2a5e525de413e3adb9da54bd5ace2699373ffdfadf3a8157
data/.rubocop.yml CHANGED
@@ -4,6 +4,9 @@ AllCops:
4
4
  Layout/CaseIndentation:
5
5
  EnforcedStyle: end
6
6
 
7
+ Layout/FirstArgumentIndentation:
8
+ EnforcedStyle: consistent
9
+
7
10
  Layout/SpaceInsideArrayLiteralBrackets:
8
11
  Enabled: false
9
12
 
@@ -17,13 +20,14 @@ Layout/LineLength:
17
20
  Metrics/BlockLength:
18
21
  ExcludedMethods:
19
22
  - it
23
+ - context
20
24
 
21
25
  Style/MultilineBlockChain:
22
26
  Enabled: false
23
27
 
24
28
  Style/NumericPredicate:
25
29
  Enabled: false
26
-
30
+
27
31
  Style/AndOr:
28
32
  Enabled: false
29
33
 
data/.travis.yml CHANGED
@@ -16,29 +16,8 @@ before_script:
16
16
 
17
17
  jobs:
18
18
  include:
19
- - stage: minitest
19
+ - stage: test
20
20
  script:
21
21
  - mkdir tmp
22
- - bundle exec rake minitest
23
-
24
- - stage: base
25
- script:
26
- - bundle exec rake build:base:2.5
27
- - stage: base
28
- script:
29
- - bundle exec rake build:base:2.6
30
-
31
- - stage: fixtures
32
- script:
33
- - bundle exec rake build:fixtures:2.5:all
34
- - stage: fixtures
35
- script:
36
- - bundle exec rake build:fixtures:2.6:all
37
-
38
- - stage: spec
39
- script:
40
- - bundle exec rake spec:2.5
41
- - stage: spec
42
- script:
43
- - bundle exec rake spec:2.6
22
+ - bundle exec rake test
44
23
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # v0.41.0
2
+
3
+ * Adjust some label names to match `provider.*`, `format.*`.
4
+ * Add global `exclude` list to *appmap.yml* which can be used to definitively exclude specific classes and methods.
5
+
6
+ # v0.40.0
7
+
8
+ * Parse source code comments into function labels.
9
+
10
+ # v0.39.2
11
+ * Correctly recognize normalized path info for subengines.
12
+
13
+ # v0.39.1
14
+ * Support Ruby 2.7.
15
+ * Remove support for Rails 4.
16
+ * Stop recommending `-t appmap` argument for `rspec`.
17
+
18
+ # v0.39.0
19
+ * Recognize and record `normalized_path_info` in Rails applications, per 1.4 AppMap format version.
20
+
21
+ # v0.38.1
22
+ * Package configuration can be `shallow`, in case which only the initial entry into the package is recorded.
23
+
1
24
  # v0.37.2
2
25
  * Fix ParameterFilter deprecation warning.
3
26
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,22 @@
1
+ # Contributing to appmap-ruby
2
+
3
+ We are incredibly thankful for the contributions we receive from the community. Before contributing, please take a moment to read our [Contributor License Agreement](https://github.com/applandorg/community/blob/master/docs/CLA%20Instructions.pdf) and our [Code of Conduct](https://github.com/applandorg/community/blob/master/docs/Code%20of%20Conduct%20for%20Contributors.pdf).
4
+
5
+ ## Contributor License Agreement
6
+ We require our external contributors to sign a Contributor License Agreement ("CLA") in order to ensure that
7
+ our projects remain licensed under Free and Open Source licenses such as while allowing
8
+ Appland to build a sustainable business.
9
+
10
+ AppLand is committed to having a true Free and Open Source Software license for our
11
+ non-commercial software. A CLA enables AppLand to safely commercialize our products while
12
+ keeping a standard FOSS license with all the rights that license grants to users.
13
+
14
+ * [Contributor License Agreement](https://github.com/applandorg/community/blob/master/docs/CLA%20Instructions.pdf)
15
+
16
+
17
+ ## Code of Conduct
18
+
19
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and
20
+ healthy community.
21
+
22
+ * [Code of Conduct](https://github.com/applandorg/community/blob/master/docs/Code%20of%20Conduct%20for%20Contributors.pdf)
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
 
2
2
  - [About](#about)
3
+ - [Supported versions](#supported-versions)
3
4
  - [Installation](#installation)
4
5
  - [Configuration](#configuration)
6
+ - [Labels](#labels)
5
7
  - [Running](#running)
6
8
  - [RSpec](#rspec)
7
9
  - [Minitest](#minitest)
8
10
  - [Cucumber](#cucumber)
9
11
  - [Remote recording](#remote-recording)
10
- - [Ruby on Rails](#ruby-on-rails)
12
+ - [AppMap for VSCode](#appmap-for-vscode)
11
13
  - [Uploading AppMaps](#uploading-appmaps)
12
14
  - [Development](#development)
13
15
  - [Running tests](#running-tests)
@@ -23,41 +25,51 @@
23
25
  "AppMap" is a data format which records code structure (modules, classes, and methods), code execution events
24
26
  (function calls and returns), and code metadata (repo name, repo URL, commit
25
27
  SHA, labels, etc). It's more granular than a performance profile, but it's less
26
- granular than a full debug trace. It's designed to be optimal for understanding the design intent and behavior of code.
28
+ granular than a full debug trace. It's designed to be optimal for understanding the design intent and structure of code and key data flows.
27
29
 
28
30
  There are several ways to record AppMaps of your Ruby program using the `appmap` gem:
29
31
 
30
- * Run your RSpec tests with the environment variable `APPMAP=true`. An AppMap will be generated for each spec.
32
+ * Run your tests (RSpec, Minitest, Cucumber) with the environment variable `APPMAP=true`. An AppMap will be generated for each spec.
31
33
  * Run your application server with AppMap remote recording enabled, and use the [AppLand
32
34
  browser extension](https://github.com/applandinc/appland-browser-extension) to start,
33
35
  stop, and upload recordings.
34
- * Run the command `appmap record <program>` to record the entire execution of a program.
36
+ * Wrap some code in an `AppMap.record` block, which returns JSON containing the code execution trace.
35
37
 
36
- Once you have recorded some AppMaps (for example, by running RSpec tests), you use the `appland upload` command
37
- to upload them to the AppLand server. This command, and some others, is provided
38
- by the [AppLand CLI](https://github.com/applandinc/appland-cli/releases).
39
- Then, on the [AppLand website](https://app.land), you can
40
- visualize the design of your code and share links with collaborators.
38
+ Once you have made a recording, there are two ways to view automatically generated diagrams of the AppMaps.
39
+
40
+ The first option is to load the diagrams directly in your IDE, using the [AppMap extension for VSCode](https://marketplace.visualstudio.com/items?itemName=appland.appmap).
41
+
42
+ The second option is to upload them to the [AppLand server](https://app.land) using the [AppLand CLI](https://github.com/applandinc/appland-cli/releases).
43
+
44
+ ### Supported versions
45
+
46
+ * Ruby 2.5, 2.6, 2.7
47
+ * Rails 5, 6
48
+
49
+ Support for new versions is added frequently, please check back regularly for updates.
41
50
 
42
51
  # Installation
43
52
 
44
- Add `gem 'appmap'` to your Gemfile just as you would any other dependency.
53
+ <a href="https://www.loom.com/share/78ab32a312ff4b85aa8827a37f1cb655"> <p>Quick and easy setup of the AppMap gem for Rails - Watch Video</p> <img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/78ab32a312ff4b85aa8827a37f1cb655-with-play.gif"> </a>
45
54
 
46
- **Global installation**
55
+
56
+ Add `gem 'appmap'` to **beginning** of your Gemfile. We recommend that you add the `appmap` gem to the `:development, :test` group. Your Gemfile should look something like this:
47
57
 
48
58
  ```
49
- gem 'appmap'
50
- ```
59
+ source 'https://rubygems.org'
60
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
51
61
 
52
- **Install in test, development groups**
62
+ # Optional rubRuby version
63
+ # ruby '2.7.2'
53
64
 
54
- ```
55
65
  group :development, :test do
56
66
  gem 'appmap'
57
67
  end
58
68
  ```
59
69
 
60
- Then install with `bundle`.
70
+ Install with `bundle install`, as usual.
71
+
72
+ It's important to add the `appmap` gem before any other gems that you may want to instrument. There is more about this in the section on adding gems to the *appmap.yml*.
61
73
 
62
74
  **Railtie**
63
75
 
@@ -65,7 +77,8 @@ If you are using Ruby on Rails, require the railtie after Rails is loaded.
65
77
 
66
78
  ```
67
79
  # application.rb is a good place to do this, along with all the other railties.
68
- require 'appmap/railtie'
80
+ # Don't require the railtie in environments that don't bundle the appmap gem.
81
+ require 'appmap/railtie' if defined?(AppMap).
69
82
  ```
70
83
 
71
84
  # Configuration
@@ -74,15 +87,28 @@ When you run your program, the `appmap` gem reads configuration settings from `a
74
87
  file for a typical Rails project:
75
88
 
76
89
  ```yaml
77
- name: MyProject
90
+ # 'name' should generally be the same as the code repo name.
91
+ name: my_project
78
92
  packages:
79
93
  - path: app/controllers
80
94
  - path: app/models
95
+ - path: app/jobs
96
+ - path: app/helpers
97
+ # Include the gems that you want to see in the dependency maps.
98
+ # These are just examples.
81
99
  - gem: activerecord
100
+ - gem: devise
101
+ - gem: aws-sdk
102
+ - gem: will_paginate
103
+ exclude:
104
+ - MyClass
105
+ - MyClass#my_instance_method
106
+ - MyClass.my_class_method
82
107
  ```
83
108
 
84
109
  * **name** Provides the project name (required)
85
- * **packages** A list of source code directories which should be instrumented.
110
+ * **packages** A list of source code directories which should be recorded.
111
+ * **exclude** A list of classes and/or methods to definitively exclude from recording.
86
112
 
87
113
  **packages**
88
114
 
@@ -90,9 +116,45 @@ Each entry in the `packages` list is a YAML object which has the following keys:
90
116
 
91
117
  * **path** The path to the source code directory. The path may be relative to the current working directory, or it may
92
118
  be an absolute path.
93
- * **gem** As an alternative to specifying the path, specify the name of a dependency gem. When using `gem`, don't specify `path`.
119
+ * **gem** As an alternative to specifying the path, specify the name of a dependency gem. When using `gem`, don't specify `path`. In your `Gemfile`, the `appmap` gem **must** be listed **before** any gem that you specify in your *appmap.yml*.
94
120
  * **exclude** A list of files and directories which will be ignored. By default, all modules, classes and public
95
- functions are inspected.
121
+ functions are inspected. See also: global `exclude` list.
122
+ * **shallow** When set to `true`, only the first function call entry into a package will be recorded. Subsequent function calls within
123
+ the same package are not recorded unless code execution leaves the package and re-enters it. Default: `true` when using `gem`,
124
+ `false` when using `path`.
125
+
126
+ **exclude**
127
+
128
+ Optional list of fully qualified class and method names. Separate class and method names with period (`.`) for class methods and hash (`#`) for instance methods.
129
+
130
+
131
+ # Labels
132
+
133
+ The [AppMap data format](https://github.com/applandinc/appmap) provides for class and function `labels`, which can be used to enhance the AppMap visualizations, and to programatically analyze the data.
134
+
135
+ You can apply function labels using source code comments in your Ruby code. To apply a labels to a function, add a `@label` or `@labels` line to the comment which immediately precedes a function.
136
+
137
+ For example, if you add this comment to your source code:
138
+
139
+ ```ruby
140
+ class ApiKey
141
+ # @labels provider.authentication security
142
+ def authenticate(key)
143
+ # logic to verify the key here...
144
+ end
145
+ end
146
+ ```
147
+
148
+ Then the AppMap metadata section for this function will include:
149
+
150
+ ```json
151
+ {
152
+ "name": "authenticate",
153
+ "type": "function",
154
+ "labels": [ "provider.authentication", "security" ]
155
+ }
156
+ ```
157
+
96
158
 
97
159
  # Running
98
160
 
@@ -119,13 +181,10 @@ require 'appmap/rspec'
119
181
  require File.expand_path("../../config/environment", __FILE__)
120
182
  ```
121
183
 
122
- 2) *Optional* Add `feature: '<feature name>'` and `feature_group: '<feature group name>'` annotations to your
123
- examples.
124
-
125
- 3) Run the tests with the environment variable `APPMAP=true`:
184
+ 2) Run the tests with the environment variable `APPMAP=true`:
126
185
 
127
186
  ```sh-session
128
- $ APPMAP=true bundle exec rspec -t appmap
187
+ $ APPMAP=true bundle exec rspec
129
188
  ```
130
189
 
131
190
  Each RSpec test will output an AppMap file into the directory `tmp/appmap/rspec`. For example:
@@ -135,23 +194,6 @@ $ find tmp/appmap/rspec
135
194
  Hello_says_hello_when_prompted.appmap.json
136
195
  ```
137
196
 
138
- If you include the `feature` and `feature_group` metadata, these attributes will be exported to the AppMap file in the
139
- `metadata` section. It will look something like this:
140
-
141
- ```json
142
- {
143
- ...
144
- "metadata": {
145
- "name": "Hello app says hello when prompted",
146
- "feature": "Hello app says hello",
147
- "feature_group": "Hello"
148
- },
149
- ...
150
- }
151
- ```
152
-
153
- If you don't explicitly declare `feature` and `feature_group`, then they will be inferred from the spec name and example descriptions.
154
-
155
197
  ## Minitest
156
198
 
157
199
  To record Minitest tests, follow these additional steps:
@@ -168,17 +210,23 @@ Note that `test_helper.rb` in a Rails project typically loads the application's
168
210
  require_relative '../config/environment'
169
211
  ```
170
212
 
171
- and `appmap/rspec` must be required before this:
213
+ and `appmap/minitest` must be required before this:
172
214
 
173
215
  ```ruby
174
- require 'appmap/rspec'
216
+ require 'appmap/minitest'
175
217
  require_relative '../config/environment'
176
218
  ```
177
219
 
178
- 2) Run the tests with the environment variable `APPMAP=true`:
220
+ 2) Run your tests as you normally would with the environment variable `APPMAP=true`. For example:
179
221
 
180
- ```sh-session
181
- $ APPMAP=true bundle exec -Ilib -Itest test/*
222
+ ```
223
+ $ APPMAP=true bundle exec rake test
224
+ ```
225
+
226
+ or
227
+
228
+ ```
229
+ $ APPMAP=true bundle exec ruby -Ilib -Itest test/*_test.rb
182
230
  ```
183
231
 
184
232
  Each Minitest test will output an AppMap file into the directory `tmp/appmap/minitest`. For example:
@@ -235,9 +283,9 @@ To manually record ad-hoc AppMaps of your Ruby app, use AppMap remote recording.
235
283
  1. Add the AppMap remote recording middleware. For example, in `config/initializers/appmap_remote_recording.rb`:
236
284
 
237
285
  ```ruby
238
- require 'appmap/middleware/remote_recording'
286
+ if defined?(AppMap)
287
+ require 'appmap/middleware/remote_recording'
239
288
 
240
- unless Rails.env.test?
241
289
  Rails.application.config.middleware.insert_after \
242
290
  Rails::Rack::Logger,
243
291
  AppMap::Middleware::RemoteRecording
@@ -258,14 +306,14 @@ $ bundle exec rails server
258
306
 
259
307
  6. Open the AppLand browser extension and push `Stop`. The recording will be transferred to the AppLand website and opened in your browser.
260
308
 
261
- ## Ruby on Rails
309
+ # AppMap for VSCode
262
310
 
263
- If your app uses Ruby on Rails, the AppMap Railtie will be automatically enabled. Set the Rails config flag `app.config.appmap.enabled = true` to record the entire execution of your Rails app.
264
-
265
- Note that using this method is kind of a blunt instrument. Recording RSpecs and using Remote Recording are usually better options.
311
+ The [AppMap extension for VSCode](https://marketplace.visualstudio.com/items?itemName=appland.appmap) is a great way to onboard developers to new code, and troubleshoot hard-to-understand bugs with visuals.
266
312
 
267
313
  # Uploading AppMaps
268
314
 
315
+ [https://app.land](https://app.land) can be used to store, analyze, and share AppMaps.
316
+
269
317
  For instructions on uploading, see the documentation of the [AppLand CLI](https://github.com/applandinc/appland-cli).
270
318
 
271
319
  # Development
data/Rakefile CHANGED
@@ -18,12 +18,12 @@ namespace 'gem' do
18
18
  require 'bundler/gem_tasks'
19
19
  end
20
20
 
21
- RUBY_VERSIONS=%w[2.5 2.6]
22
- FIXTURE_APPS=%w[rack_users_app rails6_users_app rails5_users_app rails4_users_app]
21
+ RUBY_VERSIONS=%w[2.5 2.6 2.7]
22
+ FIXTURE_APPS=%w[rack_users_app rails6_users_app rails5_users_app]
23
23
 
24
24
  def run_cmd(*cmd)
25
25
  $stderr.puts "Running: #{cmd}"
26
- out,s = Open3.capture2e(*cmd)
26
+ out, s = Open3.capture2e(*cmd)
27
27
  unless s.success?
28
28
  $stderr.puts <<-END
29
29
  Command failed:
@@ -113,17 +113,18 @@ module AppMap
113
113
  [ method.defined_class, static ? '.' : '#', method.name ].join
114
114
  end
115
115
 
116
+ source, comment = begin
117
+ [ method.source, method.comment ]
118
+ rescue MethodSource::SourceNotFoundError
119
+ [ nil, nil, ]
120
+ end
121
+
116
122
  if include_source
117
- begin
118
- function_info[:source] = method.source
119
- comment = method.comment || ''
120
- function_info[:comment] = comment unless comment.empty?
121
- rescue MethodSource::SourceNotFoundError
122
- # pass
123
- end
123
+ function_info[:source] = source unless source.blank?
124
+ function_info[:comment] = comment unless comment.blank?
124
125
  end
125
126
 
126
- function_info[:labels] = package.labels if package.labels
127
+ function_info[:labels] = parse_labels(comment) + (package.labels || [])
127
128
  object_infos << function_info
128
129
 
129
130
  parent = root
@@ -141,6 +142,22 @@ module AppMap
141
142
  end
142
143
  end
143
144
 
145
+ # Labels can be embedded in the function comment. Label format is similar to YARD and JavaDoc.
146
+ # The keyword is @labels or @label. The keyword is followed by space-separated labels.
147
+ # For example:
148
+ # @label provider.authentication security
149
+ def parse_labels(comment)
150
+ return [] unless comment
151
+
152
+ comment
153
+ .split("\n")
154
+ .map { |line| line.match(/^\s*#\s*@labels?\s+(.*)/) }
155
+ .compact
156
+ .map { |match| match[1] }
157
+ .inject([]) { |accum, labels| accum += labels.split(/\s+/); accum }
158
+ .sort
159
+ end
160
+
144
161
  def find_or_create(list, info)
145
162
  obj = list.find { |item| item.type == info[:type] && item.name == info[:name] }
146
163
  return obj if obj