Skip to content

Commit

Permalink
Always register ViewComponent event formatter
Browse files Browse the repository at this point in the history
When in a Rails application, always register the ViewComponent event
formatter, similarly to what we do with most other event formatters.

This fixes #1222, where the relative order of gems in the
application's Gemfile causes the ViewComponent event formatter to not
be loaded.
  • Loading branch information
unflxw committed Aug 1, 2024
1 parent 98fae7e commit 0f37fa3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changesets/fix-viewcomponent-instrumentation-not-loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: fix
---

Fix an issue where, depending on the relative order of the `appsignal` and `view_component` dependencies in the Gemfile, the ViewComponent instrumentation would not load.
1 change: 0 additions & 1 deletion gemfiles/rails-7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ source "https://rubygems.org"
gem "rails", "~> 7.1.0"
gem "rake", "> 12.2"
gem "sidekiq"
gem "view_component"

# Fix install issue for jruby on gem 3.1.8.
# No java stub is published.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def format(payload)
end
end

if defined?(Rails) && defined?(ViewComponent)
if defined?(Rails)
Appsignal::EventFormatter.register(
"render.view_component",
Appsignal::EventFormatter::ViewComponent::RenderFormatter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
describe Appsignal::EventFormatter::ViewComponent::RenderFormatter do
let(:klass) { Appsignal::EventFormatter::ViewComponent::RenderFormatter }

if DependencyHelper.rails_present? && DependencyHelper.view_component_present?
require "view_component"

if DependencyHelper.rails_present?
context "when in a Rails app" do
let(:formatter) { klass.new }
before { allow(Rails.root).to receive(:to_s).and_return("/var/www/app/20130101") }
Expand Down Expand Up @@ -31,7 +29,7 @@
end
end
else
context "when not in a Rails app with the ViewComponent gem" do
context "when not in a Rails app" do
it "does not register the event formatter" do
expect(Appsignal::EventFormatter.registered?("render.view_component",
klass)).to be_falsy
Expand Down
4 changes: 0 additions & 4 deletions spec/support/helpers/dependency_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ def hanami2_present?
hanami_present? && Gem.loaded_specs["hanami"].version >= Gem::Version.new("2.0")
end

def view_component_present?
dependency_present? "view_component"
end

def dependency_present?(dependency_file)
Gem.loaded_specs.key? dependency_file
end
Expand Down

0 comments on commit 0f37fa3

Please sign in to comment.