setu-trafficmonitor 2.0.0__py3-none-any.whl → 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: setu-trafficmonitor
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: A comprehensive Django app for logging HTTP requests with analytics dashboard
5
5
  Home-page: https://github.com/farmsetu/django-trafficmonitor
6
6
  Author: FarmSetu Team
@@ -1,15 +1,15 @@
1
- trafficmonitor/__init__.py,sha256=R33H15TOYxh3ql2Jo9ow4Xo_DoW48cs31ZyN9oN2qxE,277
1
+ trafficmonitor/__init__.py,sha256=WGzUAXFs_lPdm8cGBQa5S4kNZNe35S6Va_u1ZBosbW8,277
2
2
  trafficmonitor/admin.py,sha256=yZDeH2jdA0X1RU6TTkYly-3DE7HG3X23d5-rGbxyzcw,6459
3
3
  trafficmonitor/apps.py,sha256=pyeGnn-R9mU0jKZGd0FErJWZbURtpt0RO4q87HEsO9A,197
4
4
  trafficmonitor/circuit_breaker.py,sha256=zSV8vcBQrQ6_xLb04yFKuo2qtvkogvuD4p2YFY5OIFs,1911
5
- trafficmonitor/conf.py,sha256=lJfutySfKzhRpuBYN5c_UGqg0EogQ9GhWBZkS6WlNJQ,6164
5
+ trafficmonitor/conf.py,sha256=R9J3iYffTg5AqRp9mJvVLs2TbOfk1dknfH7MrDeuKSI,6377
6
6
  trafficmonitor/dashboard_security.py,sha256=6_UAhXWKru3B165Dtgj96VOYQZG1J1Mf1lVYrm-GKWU,4106
7
7
  trafficmonitor/db_utils.py,sha256=cS99U-vQqNhphxkuqH4KZq84xbs8vCRGGq45yBRSRkU,1240
8
8
  trafficmonitor/exceptions.py,sha256=ZyPjQTpWXNAmtct8xJyFFsaitQBVffVlLx90P-KjzmM,2917
9
9
  trafficmonitor/health.py,sha256=oM1rbbbKvkw2PryPTh8bRZ1ODj-1SyRWlv52DnoyWD4,2341
10
10
  trafficmonitor/load_test.py,sha256=H8dkDY3w6w8TJ2izyNtUW2Qmk8bLP05Tl7CgLpH3xzA,15078
11
11
  trafficmonitor/load_test_api.py,sha256=U1pRK8Gr-zlyP2UUNj6Z0yQx9XbVa0JywIfyYWsWJQc,11344
12
- trafficmonitor/middleware.py,sha256=3QlN7jM8bdnSnBBiRWhxjdhmX9GzKMxwCXQ4Or6Z7xI,14827
12
+ trafficmonitor/middleware.py,sha256=5CE3u2BbDAHzOpMSIhnL0C8CgvmbugdggtXXAnp8bk4,12386
13
13
  trafficmonitor/models.py,sha256=pBMuyIM9vJJzDqWaJUavgP2Djp6-I7YVFba4rNjkjWE,7192
14
14
  trafficmonitor/monitoring.py,sha256=NOJ_NUQZ-RDwhOVhhJ1CWx2FhdvfJXc0BkqqzKkCjoQ,3396
15
15
  trafficmonitor/permissions.py,sha256=uXLHGCcnhhvAbEAUe2IAMDI3sjIIPbNk-Jogv1diA64,2242
@@ -34,9 +34,9 @@ trafficmonitor/static/analytics/css/dashboard.css,sha256=_H1mlAc9wH3-xlja1HGYw9H
34
34
  trafficmonitor/static/analytics/js/dashboard-production.js,sha256=aRGgAEB7SGcZ5wBVj9G4FKwUl-t6GxxsdFDayDRw-6o,10542
35
35
  trafficmonitor/static/analytics/js/dashboard-v2.js,sha256=hZO1mUmdZK3YfCYLVX5ToaeWBfN_zPEE_T6e08fMEQM,21880
36
36
  trafficmonitor/static/analytics/js/dashboard.js,sha256=t-VfdUi8f2Bil6mIAeI-YmyBg0mMyAt5PigjQ7-I5Eo,20022
37
- trafficmonitor/templates/analytics/dashboard.html,sha256=O1vZR3oE7_19PSyrQ-GqehGWIDb7FTCcT22x60iYHio,24159
38
- setu_trafficmonitor-2.0.0.dist-info/LICENSE,sha256=UfMLKswUDNhVdUu-ul480Q3ei7XGfX_9uuAxK7OdWU4,1070
39
- setu_trafficmonitor-2.0.0.dist-info/METADATA,sha256=nzFDdITkS_2k5SjXqvbjmTabUmPqxE-YDUkIdkTntUA,12979
40
- setu_trafficmonitor-2.0.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
41
- setu_trafficmonitor-2.0.0.dist-info/top_level.txt,sha256=81-5rK9eQL1OP2I-aXy5Nd7fw7gHRKYsOfPMN2tVpVE,15
42
- setu_trafficmonitor-2.0.0.dist-info/RECORD,,
37
+ trafficmonitor/templates/analytics/dashboard.html,sha256=ylCUZsUstmi5MvzjfRkKxXneHKlod-LfgjQmVDOBzvs,24169
38
+ setu_trafficmonitor-2.0.1.dist-info/LICENSE,sha256=UfMLKswUDNhVdUu-ul480Q3ei7XGfX_9uuAxK7OdWU4,1070
39
+ setu_trafficmonitor-2.0.1.dist-info/METADATA,sha256=E98M1mtAPOJRlGDKpSmvReLuq2ho2S9pXsrVuP265yo,12979
40
+ setu_trafficmonitor-2.0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
41
+ setu_trafficmonitor-2.0.1.dist-info/top_level.txt,sha256=81-5rK9eQL1OP2I-aXy5Nd7fw7gHRKYsOfPMN2tVpVE,15
42
+ setu_trafficmonitor-2.0.1.dist-info/RECORD,,
@@ -3,7 +3,7 @@ Django TrafficMonitor
3
3
  A comprehensive Django app for logging HTTP requests with analytics dashboard
4
4
  """
5
5
 
6
- __version__ = '1.1.0'
6
+ __version__ = '2.0.1'
7
7
  __author__ = 'FarmSetu Team'
8
8
  __email__ = 'tech@farmsetu.com'
9
9
  __license__ = 'MIT'
trafficmonitor/conf.py CHANGED
@@ -145,7 +145,13 @@ class TrafficMonitorConfig:
145
145
  Returns:
146
146
  dict: {'user_id': str, 'role': str}
147
147
  """
148
+ # Primary header check (defaults to HTTP_X_USER_ID)
148
149
  user_id = request.META.get(f'HTTP_{cls.USER_ID_HEADER.replace("-", "_").upper()}')
150
+
151
+ # Fallback: standard User-Id (HTTP_USER_ID)
152
+ if not user_id:
153
+ user_id = request.META.get('HTTP_USER_ID')
154
+
149
155
  user_role = request.META.get(f'HTTP_{cls.USER_ROLE_HEADER.replace("-", "_").upper()}')
150
156
 
151
157
  return {
@@ -166,66 +166,10 @@ class RequestLoggingMiddleware(MiddlewareMixin):
166
166
  return request._body.decode('utf-8')
167
167
  elif hasattr(request, 'body'):
168
168
  return request.body.decode('utf-8')
169
- except (UnicodeDecodeError, AttributeError):
170
- pass
171
- return ""
172
-
173
- try:
174
- # Calculate response time
175
- response_time_ms = None
176
- if hasattr(request, '_logging_start_time'):
177
- response_time_ms = (time.time() - request._logging_start_time) * 1000
178
-
179
- # Calculate query count
180
- query_count = None
181
- if hasattr(request, '_logging_query_count_start'):
182
- query_count = len(connection.queries) - request._logging_query_count_start
183
-
184
- # Extract request data
185
- request_headers = self._get_request_headers(request)
186
- request_body = self._get_request_body(request)
187
-
188
- # Get user ID from header (X-User-ID)
189
- requested_user_id = request.META.get('HTTP_X_USER_ID') or request.headers.get('X-User-ID')
190
-
191
- # Get IP address
192
- ip_address = self._get_client_ip(request)
193
-
194
- # Determine operation type and endpoint category
195
- operation_type = RequestLog.get_operation_type(request.method)
196
- endpoint_category = RequestLog.extract_endpoint_category(request.path)
197
- is_api_request = request.path.startswith('/api/')
198
-
199
- # Prepare log data
200
- log_data = {
201
- 'method': request.method,
202
- 'path': request.path,
203
- 'full_url': request.build_absolute_uri(),
204
- 'status_code': response.status_code,
205
- 'requested_user_id': requested_user_id,
206
- 'ip_address': ip_address,
207
- 'user_agent': request.META.get('HTTP_USER_AGENT', ''),
208
- 'request_headers': request_headers,
209
- 'request_body': request_body,
210
- 'operation_type': operation_type,
211
- 'endpoint_category': endpoint_category,
212
- 'is_api_request': is_api_request,
213
- 'response_time_ms': response_time_ms,
214
- 'query_count': query_count,
215
- 'content_length': len(response.content) if hasattr(response, 'content') else None,
216
- }
217
-
218
- # Log asynchronously or synchronously based on config
219
- if TrafficMonitorConfig.ASYNC_LOGGING:
220
- self._log_async(log_data)
221
- else:
222
- RequestLog.objects.create(**log_data)
223
-
224
169
  except Exception as e:
225
- # Log the error but don't break the request/response cycle
226
- logger.error(f"Error logging request: {str(e)}", exc_info=True)
170
+ logger.debug(f"Error extracting request body: {str(e)}")
227
171
 
228
- return response
172
+ return None
229
173
 
230
174
  def process_exception(self, request, exception):
231
175
  """
@@ -123,14 +123,14 @@
123
123
  <label class="block text-sm font-medium text-gray-700 mb-1">Date Range</label>
124
124
  <select name="range" id="rangeSelect"
125
125
  class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
126
- <option value="today" {% if selected_range=='today' %}selected{% endif %}>Today</option>
127
- <option value="yesterday" {% if selected_range=='yesterday' %}selected{% endif %}>Yesterday
126
+ <option value="today" {% if selected_range == 'today' %}selected{% endif %}>Today</option>
127
+ <option value="yesterday" {% if selected_range == 'yesterday' %}selected{% endif %}>Yesterday
128
128
  </option>
129
- <option value="last_7_days" {% if selected_range=='last_7_days' %}selected{% endif %}>Last 7
129
+ <option value="last_7_days" {% if selected_range == 'last_7_days' %}selected{% endif %}>Last 7
130
130
  Days</option>
131
- <option value="last_30_days" {% if selected_range=='last_30_days' %}selected{% endif %}>Last 30
131
+ <option value="last_30_days" {% if selected_range == 'last_30_days' %}selected{% endif %}>Last 30
132
132
  Days</option>
133
- <option value="custom" {% if selected_range=='custom' %}selected{% endif %}>Custom Range
133
+ <option value="custom" {% if selected_range == 'custom' %}selected{% endif %}>Custom Range
134
134
  </option>
135
135
  </select>
136
136
  </div>