Skip to content

Commit dd9e383

Browse files
committed
feat: Hook the code only when APPMAP=true
If the appmap gem is loaded, but APPMAP enabled, the process initializes as normal. With APPMAP=true, all the hooking is performed, with its advantages and disadvantages.
1 parent 950835d commit dd9e383

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

lib/appmap.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ def detect_metadata
9898
end
9999

100100
require 'appmap/railtie' if defined?(::Rails::Railtie)
101-
AppMap.initialize unless ENV['APPMAP_INITIALIZE'] == 'false'
101+
AppMap.initialize if ENV['APPMAP'] == 'true'

lib/appmap/railtie.rb

+1-23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
module AppMap
44
# Railtie connects the AppMap recorder to Rails-specific features.
55
class Railtie < ::Rails::Railtie
6-
config.appmap = ActiveSupport::OrderedOptions.new
7-
86
# appmap.subscribe subscribes to ActiveSupport Notifications so that they can be recorded as
97
# AppMap events.
108
initializer 'appmap.subscribe' do |_| # params: app
@@ -15,25 +13,5 @@ class Railtie < ::Rails::Railtie
1513

1614
AppMap::Handler::Rails::RequestHandler::HookMethod.new.activate
1715
end
18-
19-
# appmap.trace begins recording an AppMap trace and writes it to appmap.json.
20-
# This behavior is only activated if the configuration setting app.config.appmap.enabled
21-
# is truthy.
22-
initializer 'appmap.trace', after: 'appmap.subscribe' do |app|
23-
lambda do
24-
return unless app.config.appmap.enabled
25-
26-
require 'appmap/command/record'
27-
require 'json'
28-
AppMap::Command::Record.new(AppMap.configuration).perform do |version, metadata, class_map, events|
29-
appmap = JSON.generate \
30-
version: version,
31-
metadata: metadata,
32-
classMap: class_map,
33-
events: events
34-
File.open('appmap.json', 'w').write(appmap)
35-
end
36-
end.call
37-
end
3816
end
39-
end unless ENV['APPMAP_INITIALIZE'] == 'false'
17+
end if ENV['APPMAP'] == 'true'

lib/appmap/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ module AppMap
55

66
VERSION = '0.47.1'
77

8-
APPMAP_FORMAT_VERSION = '1.5.0'
8+
APPMAP_FORMAT_VERSION = '1.5.1'
99
end

0 commit comments

Comments
 (0)