Skip to content

T-22151 Stop deleting the request attribute from the shared log record - #59

Merged
PetrHeinz merged 2 commits into
masterfrom
claude/t-22151-keep-request-on-record
Oct 26, 2026
Merged

PetrHeinz merged 2 commits into
masterfrom
claude/t-22151-keep-request-on-record

Conversation

@PetrHeinz

Copy link
Copy Markdown
Member

Django hands its HttpRequest to the logging handlers as extra={'request': request}: django.utils.log.log_message does it for every 4xx and 5xx response logged on django.request, and the runserver logger does the same with its socket. create_frame keeps such an object out of the JSON frame by deleting it from record.__dict__. That record is the one object every handler on the logger receives, so once LogtailHandler or LogtailFormatter has run, a later handler no longer finds record.request. Django's AdminEmailHandler then sends the error e-mail with the subject reduced to ERROR: Internal Server Error: /orders (no (EXTERNAL IP)) and a report reading Request data not supplied, and any filter or integration keyed on the request loses it the same way. A record logged with request=None loses 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_events skips a non-JSON request instead of create_frame deleting it from the record.
  • Tests for the frame (an object and 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

PetrHeinz and others added 2 commits October 26, 2026 16:02
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>
@PetrHeinz
PetrHeinz marked this pull request as ready for review October 26, 2026 15:55
@PetrHeinz
PetrHeinz merged commit 61260b0 into master Oct 26, 2026
17 checks passed
@PetrHeinz
PetrHeinz deleted the claude/t-22151-keep-request-on-record branch October 26, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant