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
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 10 | Number of results to return per page |
| offset | integer | 0 | Number of results to skip before returning results |
| search | string | — | Search in user__id, user__username, user__mobile_number, ip, device, os, browser, endpoint, or exception_type |
| ordering | string | -created_at | Field to order results by (id, user, ip, device, device_type, os, browser, endpoint, method, status_code, exception_type, duration, created_at) |
| user | integer | — | Filter by specific user ID (use 0 for anonymous users) |
| ip | string | — | Filter by IP address |
| device | string | — | Filter by device name |
| device_type | string | — | Filter by device type (pc, mobile, tablet) |
| is_bot | boolean | — | Filter by bot detection status |
| os | string | — | Filter by operating system |
| browser | string | — | Filter by browser name |
| scheme | string | — | Filter by request scheme (http, https) |
| endpoint | string | — | Filter by API endpoint |
| method | string | — | Filter by HTTP method |
| status_code | integer | — | Filter by HTTP status code |
| exception_type | string | — | Filter by exception type |
| duration_from | number | — | Minimum request duration filter (in seconds) |
| duration_to | number | — | Maximum request duration filter (in seconds) |
| has_ip | boolean | — | Filter logs with/without IP address |
| has_device | boolean | — | Filter logs with/without device information |
| has_device_type | boolean | — | Filter logs with/without device type |
| has_os | boolean | — | Filter logs with/without OS information |
| has_browser | boolean | — | Filter logs with/without browser information |
| has_scheme | boolean | — | Filter logs with/without scheme information |
| has_endpoint | boolean | — | Filter logs with/without endpoint information |
| has_method | boolean | — | Filter logs with/without HTTP method |
| has_query_params | boolean | — | Filter logs with/without query parameters |
| has_body | boolean | — | Filter logs with/without request body |
| has_status_code | boolean | — | Filter logs with/without status code |
| has_response | boolean | — | Filter logs with/without response data |
| has_request_headers | boolean | — | Filter logs with/without request headers |
| has_response_headers | boolean | — | Filter logs with/without response headers |
| has_exception_type | boolean | — | Filter logs with/without exception type |
| has_exception_message | boolean | — | Filter logs with/without exception message |
| has_exception_traceback | boolean | — | Filter logs with/without exception traceback |
| id_min | integer | — | Minimum ID filter |
| id_max | integer | — | Maximum ID filter |
| created_date | string | — | Filter by creation date (e.g., 2023-01-01) |
| updated_date | string | — | Filter by last updated date (e.g., 2023-01-01) |
| created_from | string | — | Filter by creation date range start |
| created_to | string | — | Filter by creation date range end |
| updated_from | string | — | Filter by last updated date range start |
| updated_to | string | — | Filter by last updated date range end |
Example Requests
- 🐍 Python
- 🌐 Curl
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())1# Basic listing with filters
2curl "http://www.example.com/api/metrics/request_logs?limit=50&ordering=-duration&device_type=mobile&status_code=200" \
3-H "Authorization: Token <your_api_key>"
4
5# Filter for anonymous user requests
6curl "http://www.example.com/api/metrics/request_logs?user=0&limit=20" \
7-H "Authorization: Token <your_api_key>"
8
9# Get slow requests
10curl "http://www.example.com/api/metrics/request_logs?duration_from=5.0&ordering=-duration" \
11-H "Authorization: Token <your_api_key>"Status Codes
| Code | Description |
|---|---|
| 200 | Request logs retrieved successfully |
| 400 | Bad request — invalid query parameters |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the request log |
| user | Object | User information (id, username, full_name) or null for anonymous |
| ip | String | IP address of the request |
| device | String | Device name/model |
| device_type | String | Type of device (pc, mobile, tablet) |
| is_bot | Boolean | Whether the request was made by a bot |
| os | String | Operating system information |
| browser | String | Browser information |
| scheme | String | Request scheme (http, https) |
| endpoint | String | API endpoint that was called |
| method | String | HTTP method used |
| status_code | Integer | HTTP response status code |
| exception_type | String | Type of exception (if any occurred) |
| started_at | String (ISO 8601) | Timestamp when request started |
| finished_at | String (ISO 8601) | Timestamp when request finished |
| duration | Decimal | Request duration in seconds |
| created_at | String (ISO 8601) | Timestamp when log entry was created |
| updated_at | String (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