Skip to content

Commit c766f7d

Browse files
committed
Django fix: filter out request from context
Django passes request object to log handler which is not serializable. Filter it out.
1 parent 346da7c commit c766f7d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

logtail/frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
def create_frame(record, message, context, include_extra_attributes=False):
99
r = record.__dict__
10+
# Django sends a request object in the record, which is not JSON serializable
11+
if not isinstance(r["request"], (dict, list, bool, int, float, str)) :
12+
del r["request"]
1013
frame = {}
1114
# Python 3 only solution if we ever drop Python 2.7
1215
# frame['dt'] = datetime.utcfromtimestamp(r['created']).replace(tzinfo=timezone.utc).isoformat()

logtail/handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# coding: utf-8
22
from __future__ import print_function, unicode_literals
33
import logging
4-
import multiprocessing
54

65
from .compat import queue
76
from .helpers import DEFAULT_CONTEXT

0 commit comments

Comments
 (0)