Skip to content

Commit

Permalink
Fix ValueError when getting request size in Django (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Mar 10, 2024
1 parent 24b964d commit 1e2e959
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions apitally/client/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import os
import re
import threading
Expand Down Expand Up @@ -132,15 +133,17 @@ def add_request(
self.request_counts[request_info] += 1
self.response_times.setdefault(request_info, Counter())[response_time_ms_bin] += 1
if request_size is not None:
request_size = int(request_size)
request_size_kb_bin = request_size // 1000 # In KB, rounded down to nearest 1KB
self.request_size_sums[request_info] += request_size
self.request_sizes.setdefault(request_info, Counter())[request_size_kb_bin] += 1
with contextlib.suppress(ValueError):
request_size = int(request_size)
request_size_kb_bin = request_size // 1000 # In KB, rounded down to nearest 1KB
self.request_size_sums[request_info] += request_size
self.request_sizes.setdefault(request_info, Counter())[request_size_kb_bin] += 1
if response_size is not None:
response_size = int(response_size)
response_size_kb_bin = response_size // 1000 # In KB, rounded down to nearest 1KB
self.response_size_sums[request_info] += response_size
self.response_sizes.setdefault(request_info, Counter())[response_size_kb_bin] += 1
with contextlib.suppress(ValueError):
response_size = int(response_size)
response_size_kb_bin = response_size // 1000 # In KB, rounded down to nearest 1KB
self.response_size_sums[request_info] += response_size
self.response_sizes.setdefault(request_info, Counter())[response_size_kb_bin] += 1

def get_and_reset_requests(self) -> List[Dict[str, Any]]:
data: List[Dict[str, Any]] = []
Expand Down

0 comments on commit 1e2e959

Please sign in to comment.