logstash-logger: TCP logging breaks rails when connection breaks
If we stop our ELK server while our app is running, our app will eventually stop working altogether after about 5 minutes. We are using Passenger Standalone and it doesn’t even seem to notice that anything is wrong, don’t see any helpful errors anywhere.
If we use UDP, an ELK outage is handled gracefully.
Here is our configuration for our QA environment:
config.logger = LogStashLogger.new(
type: :multi_delegator,
outputs: [
{ type: :file, path: "log/#{Rails.env}.log" },
{ type: :tcp, host: ENV["ELK_LOG_HOST"], port: ENV["ELK_LOG_PORT"]}
])
LogStashLogger.configure do |config|
config.customize_event do |event|
event["application_name"] = ENV["APPLICATION_TYPE"].present? ? ENV["APPLICATION_TYPE"] : "SentryLinkwebserver"
event["environment_name"] = Rails.env
end
end
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 24 (13 by maintainers)
@cabello If you look carefully at the stacktrace above, you’ll see that Lograge is involved here. The specific line of code is here: https://github.com/roidrage/lograge/blob/ced03c55419b7f131706b476b26be8c5cd90041b/lib/lograge/rails_ext/rack/logger.rb#L17
After each request, Lograge is forcing a flush. This is done in the foreground (application) thread. Normally, LogStashLogger will do regular flushes from a background thread in order to avoid interfering with the application thread and potentially blocking it.
It doesn’t surprise me that UDP doesn’t suffer from the same issue, because UDP is designed to not wait for a response.