Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such middleware to insert before: Rails::Rack::Logger #199

Open
gregfletch opened this issue Nov 10, 2023 · 9 comments
Open

No such middleware to insert before: Rails::Rack::Logger #199

gregfletch opened this issue Nov 10, 2023 · 9 comments

Comments

@gregfletch
Copy link

Environment

Provide at least:

  • Ruby Version: 3.2.2
  • Rails Version: 7.1.1 (branch: '7-1-stable')
  • Semantic Logger Version: 4.15.0
  • Rails Semantic Logger Version: 4.13.0
  • Other Application/framework names and versions (e.g. Puma, etc.): Puma
  • Rails configuration. Only need the settings related to Rails Semantic Logger and Semantic Logger.
  • Full Stack Trace, if an exception is being raised.

Note:

Expected Behavior

RSpec should be able to run without unhandled errors coming rails_semantic_logger.

Actual Behavior

Error occurs immediately when attempting to run rspec after updating Rails Semantic Logger to 4.13.0 and Rails from v7.0 to v7.1.
Stack Trace:

RuntimeError:
  No such middleware to insert before: Rails::Rack::Logger
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/actionpack/lib/action_dispatch/middleware/stack.rb:179:in `assert_index'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/actionpack/lib/action_dispatch/middleware/stack.rb:120:in `swap'
# /Users/user/.gem/ruby/3.2.2/gems/rails_semantic_logger-4.13.0/lib/rails_semantic_logger/engine.rb:38:in `block in <class:Engine>'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:32:in `instance_exec'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:32:in `run'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:61:in `block in run_initializers'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:50:in `each'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:50:in `tsort_each_child'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/initializable.rb:60:in `run_initializers'
# /Users/user/.gem/ruby/3.2.2/bundler/gems/rails-c742674dccf3/railties/lib/rails/application.rb:423:in `initialize!'
# ./config/environment.rb:7:in `<top (required)>'
# /Users/user/.gem/ruby/3.2.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /Users/user/.gem/ruby/3.2.2/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/rails_helper.rb:6:in `<top (required)>'
# /Users/user/.gem/ruby/3.2.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /Users/user/.gem/ruby/3.2.2/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'

Pull Request

  • Consider submitting a Pull Request with a fix for the issue.
    • This is particularly helpful when running newer Rails versions, since we are not running it yet.
  • Or, even a Pull request that only includes a test that reproduces the problem.
@reidmorrison
Copy link
Owner

There was a community supplied PR submitted to switch to Rackup, want to give it a try with the new Rails Semantic Logger v4.14.0?

@davidgm0
Copy link

I've had the same error with v4.14.0

@jasonkarns
Copy link

jasonkarns commented Nov 17, 2023

we also get this error with:
rails_semantic_logger (4.14.0)
semantic_logger (4.15.0)
rails (7.1.2)
rack (3.0.8)

@gregfletch
Copy link
Author

No longer seeing this issue after updating to the latest version from the Rails '7-1-stable' branch and latest version of rails_semantic_logger.

@mkamensky
Copy link

Same issue here with rails 7.1.3.2

@rsanheim
Copy link

We are seeing this against a large monolith using Rails 6.1.7.6.

@zokioki
Copy link

zokioki commented May 17, 2024

We are also seeing this issue:

  • ruby 3.1.4
  • rails 7.1.3.3
  • rails_semantic_logger 4.14.0
  • semantic_logger 4.15.0
  • rack 2.2.9

@pironim
Copy link

pironim commented Jun 3, 2024

I face this issue during upgrade from ruby 2.7 to 3.0 without any changes to gem versions
After some back and forth realize that problem was in a different place.
in my case undef for method inside application controller did not work and error was silently suppressed.

rails 6.1.7
ruby 3.0
rails_semantic_logger 4.14.0
semantic_logger 4.15.0

I think it not related to semantic logger itself

@jsp
Copy link

jsp commented Dec 6, 2024

I just did a first time install using ruby 3.3.6, rails 7.1.5, rails_semantic_logger 4.17.0 and semantic_logger 4.16.1. rails c kept failing with [...]gems/actionpack-7.1.5/lib/action_dispatch/middleware/stack.rb:179:in 'assert_index': No such middleware to insert before: Rails::Rack::Logger (RuntimeError).

With some Googling I realized this was due to a conflict with the gem Silencer, which initialized with:

require 'silencer/rails/logger'

Rails.application.configure do
  config.middleware.swap(
    Rails::Rack::Logger, 
    Silencer::Logger, 
    config.log_tags,
    silence: ["/heartbeat"]
  )
end

Removing this cleared up the error and logging worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants