Skip to main content

List Request Logs

Retrieves a list of all request logs with filtering, searching, and ordering capabilities. This endpoint provides comprehensive logging information for API requests including user data, device information, response details, and performance metrics.

HTTP Request

GET/api/metrics/request_logs

Authorization

Authorization

  • Required: Yes
  • Permission: Staff or Admin
  • Authentication: Token authentication

Query Parameters

ParameterTypeDefaultDescription
limitinteger10Number of results to return per page
offsetinteger0Number of results to skip before returning results
searchstringSearch in user__id, user__username, user__mobile_number, ip, device, os, browser, endpoint, or exception_type
orderingstring-created_atField to order results by (id, user, ip, device, device_type, os, browser, endpoint, method, status_code, exception_type, duration, created_at)
userintegerFilter by specific user ID (use 0 for anonymous users)
ipstringFilter by IP address
devicestringFilter by device name
device_typestringFilter by device type (pc, mobile, tablet)
is_botbooleanFilter by bot detection status
osstringFilter by operating system
browserstringFilter by browser name
schemestringFilter by request scheme (http, https)
endpointstringFilter by API endpoint
methodstringFilter by HTTP method
status_codeintegerFilter by HTTP status code
exception_typestringFilter by exception type
duration_fromnumberMinimum request duration filter (in seconds)
duration_tonumberMaximum request duration filter (in seconds)
has_ipbooleanFilter logs with/without IP address
has_devicebooleanFilter logs with/without device information
has_device_typebooleanFilter logs with/without device type
has_osbooleanFilter logs with/without OS information
has_browserbooleanFilter logs with/without browser information
has_schemebooleanFilter logs with/without scheme information
has_endpointbooleanFilter logs with/without endpoint information
has_methodbooleanFilter logs with/without HTTP method
has_query_paramsbooleanFilter logs with/without query parameters
has_bodybooleanFilter logs with/without request body
has_status_codebooleanFilter logs with/without status code
has_responsebooleanFilter logs with/without response data
has_request_headersbooleanFilter logs with/without request headers
has_response_headersbooleanFilter logs with/without response headers
has_exception_typebooleanFilter logs with/without exception type
has_exception_messagebooleanFilter logs with/without exception message
has_exception_tracebackbooleanFilter logs with/without exception traceback
id_minintegerMinimum ID filter
id_maxintegerMaximum ID filter
created_datestringFilter by creation date (e.g., 2023-01-01)
updated_datestringFilter by last updated date (e.g., 2023-01-01)
created_fromstringFilter by creation date range start
created_tostringFilter by creation date range end
updated_fromstringFilter by last updated date range start
updated_tostringFilter by last updated date range end

Example Requests

1import requests
2
3# Basic request logs listing with authentication
4response = requests.get('http://www.example.com/api/metrics/request_logs', 
5  params={
6      'limit': 50,
7      'ordering': '-duration',
8      'search': 'smartphone',
9      'user': 123,
10      'device_type': 'mobile',
11      'status_code': 200,
12      'duration_from': 1.0,
13      'has_exception_type': False
14  },
15  headers={'Authorization': 'Token <your_api_key>'}
16)
17print(response.json())
18
19# Filter for error logs only
20response = requests.get('http://www.example.com/api/metrics/request_logs', 
21  params={
22      'limit': 20,
23      'ordering': '-created_at',
24      'has_exception_type': True,
25      'created_from': '2023-01-01T00:00:00Z'
26  },
27  headers={'Authorization': 'Token <your_api_key>'}
28)
29print(response.json())

Status Codes

CodeDescription
200Request logs retrieved successfully
400Bad request — invalid query parameters
401Unauthorized — authentication required
403Forbidden — insufficient permissions
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the request log
userObjectUser information (id, username, full_name) or null for anonymous
ipStringIP address of the request
deviceStringDevice name/model
device_typeStringType of device (pc, mobile, tablet)
is_botBooleanWhether the request was made by a bot
osStringOperating system information
browserStringBrowser information
schemeStringRequest scheme (http, https)
endpointStringAPI endpoint that was called
methodStringHTTP method used
status_codeIntegerHTTP response status code
exception_typeStringType of exception (if any occurred)
started_atString (ISO 8601)Timestamp when request started
finished_atString (ISO 8601)Timestamp when request finished
durationDecimalRequest duration in seconds
created_atString (ISO 8601)Timestamp when log entry was created
updated_atString (ISO 8601)Timestamp when log entry was last updated

Notes

    • The duration field is automatically calculated from started_at and finished_at timestamps
    • Anonymous requests are stored with user: null and can be filtered using user=0 parameter
    • Use boolean has_* filters to find logs with or without specific data fields
    • Search works across multiple fields including user information, device details, and endpoints
    • Performance monitoring: use duration_from and duration_to to identify slow requests
    • Error tracking: use has_exception_type=true to filter for failed requests
    • Bot detection: use is_bot filter to separate bot traffic from human users