-
-
Notifications
You must be signed in to change notification settings - Fork 356
Open
Description
I wish to save only requests and responses with a 500 response status code.
Right now my solution is to use my own middleware and override _process_response:
@transaction.atomic(using=router.db_for_write(models.SQLQuery))
def _process_response(self, request, response):
Logger.debug('Process response')
with silk_meta_profiler():
collector = DataCollector()
collector.stop_python_profiler()
silk_request = collector.request
if silk_request:
if response.status_code in settings.SILKY_INTERCEPT_STATUS_CODES:
ResponseModelFactory(response).construct_response_model()
silk_request.end_time = timezone.now()
collector.finalise()
else:
silk_request.delete()
silk_request = None
else:
Logger.error(
'No request model was available when processing response. '
'Did something go wrong in process_request/process_view?'
'\n' + str(request) + '\n\n' + str(response)
)
# Need to save the data outside the silk_meta_profiler
# Otherwise the meta time collected in the context manager
# is not taken in account
if silk_request:
silk_request.save()
Logger.debug('Process response done.')Then in my settings file:
SILKY_INTERCEPT_STATUS_CODES = {500}It would be better if the request object was not created in the first place.
And if django-silk supported something like this out of the box.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels