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

Task/rollback release 2.0.1 #471

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1192ab2
Merge pull request #393 from epimorphics/task/rc-v1.7.3
jonrandahl Mar 15, 2024
63d727c
Merge pull request #395 from epimorphics/task/release-v1.7.3
jonrandahl Apr 3, 2024
eb508b9
Merge branch 'dev' into task/release-candidate-v1.7.4
jonrandahl Apr 30, 2024
ebf51ae
docs: updated CHANGELOG
jonrandahl Apr 30, 2024
693aaa6
Merge pull request #402 from epimorphics/task/release-candidate-v1.7.4
jonrandahl May 1, 2024
856f779
Merge remote-tracking branch 'origin/preprod' into task/release-v1.7.4
jonrandahl May 1, 2024
2c29b17
Merge pull request #403 from epimorphics/task/release-v1.7.4
jonrandahl May 20, 2024
3fb3658
Merge remote-tracking branch 'origin/dev' into task/release-candidate…
jonrandahl Sep 6, 2024
e50eca7
Merge pull request #447 from epimorphics/task/release-candidate-1.7.5
jonrandahl Sep 6, 2024
61026ac
Merge pull request #453 from epimorphics/dev
bogdanadrianmarc Sep 24, 2024
1ad3bda
Merge pull request #454 from epimorphics/preprod
bogdanadrianmarc Oct 1, 2024
bd65dae
refactor: renamed `render_error` method to `handle_error`
jonrandahl Oct 9, 2024
5322aa4
refactor: adjusted internal error instrumentation
jonrandahl Oct 9, 2024
9b9afbe
refactor: adjusted application error reporting
jonrandahl Oct 9, 2024
a8804e3
build: updated the version patch cadence
jonrandahl Oct 9, 2024
8341e4a
docs: Updated CHANGELOG
jonrandahl Oct 9, 2024
bf6c18d
Merge pull request #457 from epimorphics/hotfix/reduce-log-noise
jonrandahl Oct 9, 2024
49c1fed
Merge pull request #460 from epimorphics/dev
bogdanadrianmarc Nov 19, 2024
5127675
Merge branch 'prod' into preprod
bogdanadrianmarc Nov 20, 2024
4d04030
Merge branch 'dev' into preprod
bogdanadrianmarc Nov 21, 2024
4e185ff
Merge pull request #461 from epimorphics/preprod
bogdanadrianmarc Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

- (Dan) Updates ruby version to 2.7.8 and alpine version to 3.16 [GH-455](https://github.com/epimorphics/ukhpi/issues/455)

## 1.7.6 - 2024-10

- (Jon) Split the error logging into it's own method as well as adjusted the
logged message to be either the response message or the response status
- (Jon) Renamed `render_error` method to `handle_error`
- (Jon) Set the Internal Error Instrumentation to an `unless` statement to
ensure the application does not report internal errors to the Prometheus
metrics when the error is a 404 thereby reducing the noise in the Slack alerts
channel

## 1.7.5 - 2024-09

- (Jon) Created a `local` makefile target to allow for local development without
Expand Down Expand Up @@ -113,7 +123,7 @@
- (Bogdan) Added alt text to application logo
[GH-404](https://github.com/epimorphics/ukhpi/issues/404)

## 1.7.4 - 2024-04-19
## 1.7.4 - 2024-05-01

- (Jon) Updated print presenter to use
[`.try(:first)`](https://apidock.com/rails/Object/try) which resolves by
Expand Down
24 changes: 16 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def log_request_result

private

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def detailed_request_log(duration)
env = request.env

Expand All @@ -54,20 +54,28 @@ def detailed_request_log(duration)
body: request.body.gets&.gsub("\n", '\n'),
method: request.method,
status: response.status,
message: Rack::Utils::HTTP_STATUS_CODES[response.status]
message: response.message || Rack::Utils::HTTP_STATUS_CODES[response.status]
}

case response.status
when 500..599
if (500..599).include?(Rack::Utils::SYMBOL_TO_STATUS_CODE[response.status])
log_fields[:message] = env['action_dispatch.exception'].to_s
Rails.logger.error(JSON.generate(log_fields))
end

log_response(response.status, log_fields)
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

# Log the error with the appropriate log level based on the status code
def log_response(status, error_log)
case status
when 500..599
Rails.logger.error(JSON.generate(error_log))
when 400..499
Rails.logger.warn(JSON.generate(log_fields))
Rails.logger.warn(JSON.generate(error_log))
else
Rails.logger.info(JSON.generate(log_fields))
Rails.logger.info(JSON.generate(error_log))
end
end
# rubocop:enable Metrics/AbcSize

# Notify subscriber(s) of an internal error event with the payload of the
# exception once done
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/exceptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
class ExceptionsController < ApplicationController
layout 'application'

def render_error
def handle_error
env = request.env
exception = env['action_dispatch.exception']
status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code

sentry_code = maybe_report_to_sentry(exception, status_code)
# add the exception to the prometheus metrics
instrument_internal_error(exception)

# add the exception to the prometheus metrics but only on errors that are 404
instrument_internal_error(exception) unless status_code == 404

render :error_page,
locals: { status: status_code, sentry_code: sentry_code },
Expand All @@ -22,7 +23,7 @@ def render_error
private

def maybe_report_to_sentry(exception, status_code)
return nil if Rails.env.development? # Why are we reporting to Senty in dev?
return nil if Rails.env.development? # Why are we reporting to Sentry in dev?
return nil unless status_code >= 500

sevent = Sentry.capture_exception(exception)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Custom error handling via a Rack middleware action
Rails.application.config.exceptions_app =
lambda do |env|
ExceptionsController.action(:render_error).call(env)
ExceptionsController.action(:handle_error).call(env)
end