Log a response row with status 500 when the app raises - #27
Merged
Merged
Conversation
HTTPEvents calls the app without a rescue, so a request whose app raises gets a request row but never an http_response_sent row: no status and no duration, and 5xx responses are never recorded. The tests pin the new behaviour: exactly one response row with status 500 and the duration up to the exception, in normal and collapsed mode, with the original exception re-raised unchanged; a status_for_exception resolver for the status; and 500 when the resolver raises itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HTTPEvents now rescues Exception around the app call, logs the http_response_sent event in normal and collapsed mode, and re-raises the original exception unchanged. The row has the duration up to the exception, no headers or body, and the status from the new status_for_exception setting: a callable that receives the exception, 500 by default (DEFAULT_STATUS_FOR_EXCEPTION), and 500 when the callable raises itself. Building that row can't replace the app's exception: a failure goes to the debug logger only. Adds a test for that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
PetrHeinz
marked this pull request as ready for review
October 2, 2026 09:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTPEventscalls the app without a rescue, so when the app raises, the request gets aStarted …row but never anhttp_response_sentrow: no status, no duration. 5xx responses are never recorded, and dashboards or alerts on status 500 never fire. Yesterday's red-team saw this in Rack, Sinatra and on every Rails version: a controller raisingRuntimeErrorproduced the request row and the error row, and no response row at all.What changes:
HTTPEventsrescuesExceptionaround the app call, logs the response event, and re-raises the original exception unchanged (same object, same backtrace).HTTPEvents.status_for_exceptionsetting and the duration up to the exception. It has no headers, body or content length. It is logged in normal mode (after the request row) and as the single event in collapsed mode, where the message readsGET /path completed with 500 Internal Server Error in 12.3ms.status_for_exceptionis a callable that receives the exception and returns an Integer status. It defaults toDEFAULT_STATUS_FOR_EXCEPTION, which returns 500. If the callable raises itself, the row gets 500 and the error goes toLogtail::Config.instance.debug. Setting a value that doesn't respond to#callraisesArgumentErrorat configuration time, likesilence_request.Behaviour and compatibility:
status_for_exception; the logtail-rails integration will set it fromconfig.action_dispatch.rescue_responses(separate PR), soActiveRecord::RecordNotFoundis logged as 404 there.Targets the 0.2.9 patch release. The logtail-rails PR for exception statuses runs its CI against this branch until 0.2.9 is released.
The first commit only adds the tests and is expected to fail on CI; the second commit makes them pass.
🤖 Generated with Claude Code