Skip to content

Commit

Permalink
Fix Padrino instrumentation causing boot loop
Browse files Browse the repository at this point in the history
Apply the same boot loop fix as for Sinatra for Padrino from PR #1105.

For Sinatra apps noticed in our test setup that when I added a Sinatra
app to the Rails app, and loaded the Sinatra instrumentation as
specified in our docs it would get stuck in a boot loop. This was caused
by the two different configs overwriting each other every time.

Apply the same fix for Padrino by checking first if AppSignal has
already started and skipping the auto start.
  • Loading branch information
tombruijn committed Jul 3, 2024
1 parent 9239c26 commit e19e613
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changesets/padrino-boot-loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
type: fix
---

Fix issue with AppSignal getting stuck in a boot loop when loading the Padrino integration with: `require "appsignal/integrations/padrino"`
This could happen in nested applications, like a Padrino app in a Rails app. AppSignal will now use the first config AppSignal starts with.
8 changes: 5 additions & 3 deletions lib/appsignal/integrations/padrino.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def self.init
Padrino.before_load do
Appsignal.internal_logger.debug("Loading Padrino (#{Padrino::VERSION}) integration")

root = Padrino.mounted_root
Appsignal.config = Appsignal::Config.new(root, Padrino.env)
Appsignal.start
unless Appsignal.active?
root = Padrino.mounted_root
Appsignal.config = Appsignal::Config.new(root, Padrino.env)
Appsignal.start
end

next unless Appsignal.active?

Expand Down
31 changes: 31 additions & 0 deletions spec/lib/appsignal/integrations/padrino_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ def uninstall_padrino_integration
end
end

context "when already active" do
before { allow(Appsignal).to receive(:active?).and_return(true) }

it "does not start AppSignal again" do
expect(Appsignal::Config).to_not receive(:new)
expect(Appsignal).to_not receive(:start)

Appsignal::Integrations::PadrinoPlugin.init
callbacks[:before_load].call
end

it "adds the instrumentation middleware to Sinatra::Base" do
Appsignal::Integrations::PadrinoPlugin.init
callbacks[:before_load].call

middlewares = Padrino.middleware
expect(middlewares).to include(
[Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
)
expect(middlewares).to include(
[
Appsignal::Rack::SinatraBaseInstrumentation,
[
:instrument_span_name => "process_action.padrino"
],
nil
]
)
end
end

context "with active config" do
before do
ENV["APPSIGNAL_APP_NAME"] = "My Padrino app name"
Expand Down

0 comments on commit e19e613

Please sign in to comment.