Repository navigation
T-22151 Stop deleting the request attribute from the shared log record - #59
Merged
Merged
Conversation
create_frame deletes a non-JSON request from the shared LogRecord, so the next handler on the logger (such as Django's AdminEmailHandler) no longer finds record.request. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The request check moves from create_frame, which deleted a non-JSON request from record.__dict__, into _parse_custom_events, which skips it in the frame and leaves the record intact for the other handlers on the logger. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Django hands its
HttpRequestto the logging handlers asextra={'request': request}:django.utils.log.log_messagedoes it for every 4xx and 5xx response logged ondjango.request, and the runserver logger does the same with its socket.create_framekeeps such an object out of the JSON frame by deleting it fromrecord.__dict__. That record is the one object every handler on the logger receives, so onceLogtailHandlerorLogtailFormatterhas run, a later handler no longer findsrecord.request. Django'sAdminEmailHandlerthen sends the error e-mail with the subject reduced toERROR: Internal Server Error: /orders(no(EXTERNAL IP)) and a report readingRequest data not supplied, and any filter or integration keyed on the request loses it the same way. A record logged withrequest=Noneloses the attribute too.The request check moves into the custom-event extraction, where the field is skipped while the record stays untouched. The frame itself does not change: a request that is a dict, list, bool, int, float or str is still included, anything else is still left out.
logtail/frame.py:_parse_custom_eventsskips a non-JSONrequestinstead ofcreate_framedeleting it from the record.None), the formatter and the handler, the latter two checking that the next handler on the logger still sees the same request object.The first commit holds only the tests and is expected to fail CI with
AttributeError: 'LogRecord' object has no attribute 'request'.Refs #57
🤖 Generated with Claude Code