Comments (8)
Ok, so it looks like ActiveRecord::RecordNotFound is being reported as a 500 error by lograge which is clearly not what is being sent. I get that extract_status is making a guess but in this case it's guessing wrong. And this is the only 500 error in the logs. Other 500 errors show as a stack trace. 404 errors caused by missing routes (ActionController::RoutingError) are also logged as a stack trace.
from lograge.
Does your application ignore RecordNotFound and turn them into a 404?
If lograge (currently) doesn't receive a status code from the controller, but finds an exception, it outputs that to the logs. With the RecordNotFound it doesn't seem to be getting a status code in your case.
from lograge.
This app is Rails 3.2.11 and uses exception_notification 2.6.1. Other than that there is no special handling of 404 or 500 errors.
There are 2 separate issues I've run into:
- Stack trace errors in logs with ActionController::RoutingError and any 500 exception. I've still not resolved this.
- RecordNotFound errors logged as 500 instead of 404. This can be fixed by changing the following in extract_status:
{ :status => 500, :error => "#{exception}:#{message}" }
to:
{
:status => ActionDispatch::ExceptionWrapper.new({}, exception.constantize.new).status_code,
:error => "#{exception}:#{message}"
}
from lograge.
lograge doesn't concern itself with dumping the stacktrace to the logs, happy to be proven wrong, but dumping a stacktrace to the logs on a 500 error is common Rails behaviour.
I can look into using ExceptionWrapper to determine the status code.
from lograge.
Yes, the issue is not so much the stack trace but the fact that there is no log line for the request which caused it. I believe this is because those exceptions are not caught and logged until the debug_exceptions middleware which is outside the scope of ActiveSupport::LogSubscriber. It's worth mentioning because I assumed, incorrectly, that all 404 and 500 errors would be logged by lograge but they are not. So the behaviour was not what I expected and perhaps that may be the case for others. Still it's a great idea and I appreciate you putting it out there.
from lograge.
I do something like
if event.payload[:exception] && strace = event.payload[:stacktrace]
quoted_stacktrace = %('#{Array(strace).join("\n\t")}') # depending on if I'm logging as logstash or not
opts[:stacktrace] = quoted_stacktrace
# will output as e.g.
# "stacktrace":"'[\"/Users/somedev/.rvm/gems/ etc.
# no need to include the :exception payload as it is already output
# by the 'error' key, e.g.
# "error":"ActionView::Template::Error:bootstrap/carousel.js isn't precompiled"
end
require "active_support/notifications/instrumenter"
# https://github.com/rails/rails/blob/4-2-stable/activesupport/lib/active_support/notifications/instrumenter.rb
# also see payload[:stacktrace] in config/application.rb
# below per Carl Lerche to preserve skylight patch and our patch
# https://gist.github.com/carllerche/acd5c34e284d90678ac0
class ActiveSupport::Notifications::Instrumenter
# :nocov:
alias_method :instrument_original, :instrument
# rubocop:disable Lint/RescueException
def instrument(name, payload = {})
instrument_original(name, payload) do
begin
yield
rescue Exception => e
# BF added the below line to include backtrace in lograge
payload[:stacktrace] = e.backtrace
raise
end
end
end
# rubocop:enable Lint/RescueException
# :nocov:
end
# look into adding an exception object via middleware that we can
# use in the :append_info_to_payload method
# e.g. see
# https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rails/action_controller_catcher.rb#L7
# and https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rails/error_lookup.rb#L7
# https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rails/middleware.rb#L13
# and https://github.com/airbrake/airbrake/blob/master/lib/airbrake/railtie.rb
# and https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rack.rb#L44
# since there is a difference between what is available by a subscriber and a middleware
# see https://github.com/roidrage/lograge/blob/master/lib/lograge.rb
from lograge.
@bf4 , where do you put the above lines of code?
from lograge.
I think this is fixed as of #112?
from lograge.
Related Issues (20)
- No logs shown in CloudWatch when lograge is enabled (Rails/ECS/Fargate) HOT 1
- Why are we striping params for redirect url?
- [Question] Project status HOT 2
- Monkey patching of Rails::Rack::Logger#call_app loses request.action_dispatch instrumentation HOT 1
- [Question] Logstash-event loaded from gh
- How to add extra log payload in action cable?
- Rails support HOT 1
- Should we demote some of our formatters to "contrib"?
- Unable to Filter ActionCable Params HOT 2
- exception cannot show on rescue_from custom handler exception HOT 1
- custom_payload is "persisted' (or per se kept) between 2 requests HOT 4
- Request: new gem release HOT 5
- Any thoughts on supporting `Turbo::StreamsChannel`? HOT 1
- Sinatra support? HOT 1
- Simpler way to remove all log subscribers. HOT 3
- Redirect in routes not handled by lograge
- Confused about what Rails logging is eliminated HOT 1
- ActionView logs not completely suppressed with Rails 7.1+
- TypeError: no implicit conversion of String into Integer when adding lograge to Rails project with Rack 3.0.9 and Puma 6.4.2 HOT 3
- Suggestion from Rails regarding better patching mechanism
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lograge.