Skip to content

Commit

Permalink
fix: instrumentation of Rails 7
Browse files Browse the repository at this point in the history
ActionView instrumentation no longer fails by having it use the same
subscriber logic as used for Rails 6.

Also add Rails 7 Appraisals to all relevant gems which has any Rails
Appraisals.
  • Loading branch information
jimeh committed Oct 25, 2021
1 parent b28891b commit d2f100b
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 1 deletion.
4 changes: 4 additions & 0 deletions instrumentation/action_pack/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ end
appraise 'rails-6.1' do
gem 'rails', '~> 6.1.0'
end

appraise 'rails-7.0' do
gem 'rails', '~> 7.0.0.alpha2'
end
1 change: 1 addition & 0 deletions instrumentation/action_pack/gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "rails", "~> 5.2.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-base", path: "../../../instrumentation/base"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_pack/gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "rails", "~> 6.0.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-base", path: "../../../instrumentation/base"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_pack/gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "rails", "~> 6.1.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-base", path: "../../../instrumentation/base"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
Expand Down
18 changes: 18 additions & 0 deletions instrumentation/action_pack/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "rails", "~> 7.0.0.alpha2"

group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-base", path: "../../../instrumentation/base"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
end

gemspec path: "../"
13 changes: 13 additions & 0 deletions instrumentation/action_pack/test/test_helpers/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def initialize_app(use_exceptions_app: false, remove_rack_tracer_middleware: fal
apply_rails_6_0_configs(new_app)
when /^6\.1/
apply_rails_6_1_configs(new_app)
when /^7\./
apply_rails_7_configs(new_app)
end

remove_rack_middleware(new_app) if remove_rack_tracer_middleware
Expand Down Expand Up @@ -78,4 +80,15 @@ def apply_rails_6_1_configs(application)
# Required in Rails 6
application.config.hosts << 'example.org'
end

def apply_rails_7_configs(application)
# Required in Rails 7
application.config.hosts << 'example.org'

# Unfreeze values which may have been frozen on previous initializations.
ActiveSupport::Dependencies.autoload_paths =
ActiveSupport::Dependencies.autoload_paths.dup
ActiveSupport::Dependencies.autoload_once_paths =
ActiveSupport::Dependencies.autoload_once_paths.dup
end
end
4 changes: 4 additions & 0 deletions instrumentation/action_view/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ end
appraise 'rails-6.1' do
gem 'rails', '~> 6.1.0'
end

appraise 'rails-7.0' do
gem 'rails', '~> 7.0.0.alpha2'
end
17 changes: 17 additions & 0 deletions instrumentation/action_view/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "rails", "~> 7.0.0.alpha2"

group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module ActionView
def self.subscribe(pattern = nil, callable = nil)
ActiveSupport::Notifications.subscribe(pattern, callable)
::ActiveSupport::Notifications.notifier.synchronize do
if ::Rails::VERSION::MAJOR == 6
if ::Rails::VERSION::MAJOR >= 6
s = ::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern].pop
::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern].unshift(s)
else
Expand Down
4 changes: 4 additions & 0 deletions instrumentation/rails/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ end
appraise 'rails-6.1' do
gem 'rails', '~> 6.1.0'
end

appraise 'rails-7.0' do
gem 'rails', '~> 7.0.0.alpha2'
end
2 changes: 2 additions & 0 deletions instrumentation/rails/gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ gem "rails", "~> 5.2.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-action_pack", path: "../../../instrumentation/action_pack"
gem "opentelemetry-instrumentation-action_view", path: "../../../instrumentation/action_view"
gem "opentelemetry-instrumentation-active_record", path: "../../../instrumentation/active_record"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/rails/gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ gem "rails", "~> 6.0.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-action_pack", path: "../../../instrumentation/action_pack"
gem "opentelemetry-instrumentation-action_view", path: "../../../instrumentation/action_view"
gem "opentelemetry-instrumentation-active_record", path: "../../../instrumentation/active_record"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/rails/gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ gem "rails", "~> 6.1.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-action_pack", path: "../../../instrumentation/action_pack"
gem "opentelemetry-instrumentation-action_view", path: "../../../instrumentation/action_view"
gem "opentelemetry-instrumentation-active_record", path: "../../../instrumentation/active_record"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
Expand Down
21 changes: 21 additions & 0 deletions instrumentation/rails/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "rails", "~> 7.0.0.alpha2"

group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-action_pack", path: "../../../instrumentation/action_pack"
gem "opentelemetry-instrumentation-action_view", path: "../../../instrumentation/action_view"
gem "opentelemetry-instrumentation-active_record", path: "../../../instrumentation/active_record"
gem "opentelemetry-instrumentation-rack", path: "../../../instrumentation/rack"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
end

gemspec path: "../"
13 changes: 13 additions & 0 deletions instrumentation/rails/test/test_helpers/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def initialize_app(use_exceptions_app: false, remove_rack_tracer_middleware: fal
apply_rails_6_0_configs(new_app)
when /^6\.1/
apply_rails_6_1_configs(new_app)
when /^7\./
apply_rails_7_configs(new_app)
end

remove_rack_middleware(new_app) if remove_rack_tracer_middleware
Expand Down Expand Up @@ -78,4 +80,15 @@ def apply_rails_6_1_configs(application)
# Required in Rails 6
application.config.hosts << 'example.org'
end

def apply_rails_7_configs(application)
# Required in Rails 7
application.config.hosts << 'example.org'

# Unfreeze values which may have been frozen on previous initializations.
ActiveSupport::Dependencies.autoload_paths =
ActiveSupport::Dependencies.autoload_paths.dup
ActiveSupport::Dependencies.autoload_once_paths =
ActiveSupport::Dependencies.autoload_once_paths.dup
end
end

0 comments on commit d2f100b

Please sign in to comment.