apitally 0.12.0__py3-none-any.whl → 0.12.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.
apitally/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.12.0"
1
+ __version__ = "0.12.1"
apitally/litestar.py CHANGED
@@ -72,16 +72,31 @@ class ApitallyPlugin(InitPluginProtocol):
72
72
  response_time = 0.0
73
73
  response_headers = Headers()
74
74
  response_body = b""
75
+ response_size = 0
76
+ response_chunked = False
75
77
  start_time = time.perf_counter()
76
78
 
77
79
  async def send_wrapper(message: Message) -> None:
78
- nonlocal response_time, response_status, response_headers, response_body
80
+ nonlocal \
81
+ response_time, \
82
+ response_status, \
83
+ response_headers, \
84
+ response_body, \
85
+ response_size, \
86
+ response_chunked
79
87
  if message["type"] == "http.response.start":
80
88
  response_time = time.perf_counter() - start_time
81
89
  response_status = message["status"]
82
90
  response_headers = Headers(message["headers"])
83
- elif message["type"] == "http.response.body" and response_status == 400:
84
- response_body += message["body"]
91
+ response_chunked = (
92
+ response_headers.get("Transfer-Encoding") == "chunked"
93
+ or "Content-Length" not in response_headers
94
+ )
95
+ elif message["type"] == "http.response.body":
96
+ if response_chunked:
97
+ response_size += len(message.get("body", b""))
98
+ if response_status == 400:
99
+ response_body += message.get("body", b"")
85
100
  await send(message)
86
101
 
87
102
  await app(scope, receive, send_wrapper)
@@ -91,6 +106,7 @@ class ApitallyPlugin(InitPluginProtocol):
91
106
  response_time=response_time,
92
107
  response_headers=response_headers,
93
108
  response_body=response_body,
109
+ response_size=response_size,
94
110
  )
95
111
  else:
96
112
  await app(scope, receive, send) # pragma: no cover
@@ -104,6 +120,7 @@ class ApitallyPlugin(InitPluginProtocol):
104
120
  response_time: float,
105
121
  response_headers: Headers,
106
122
  response_body: bytes,
123
+ response_size: int = 0,
107
124
  ) -> None:
108
125
  if response_status < 100 or not request.route_handler.paths:
109
126
  return # pragma: no cover
@@ -120,7 +137,7 @@ class ApitallyPlugin(InitPluginProtocol):
120
137
  status_code=response_status,
121
138
  response_time=response_time,
122
139
  request_size=request.headers.get("Content-Length"),
123
- response_size=response_headers.get("Content-Length"),
140
+ response_size=response_size or response_headers.get("Content-Length"),
124
141
  )
125
142
  if response_status == 400 and response_body and len(response_body) < 4096:
126
143
  with contextlib.suppress(json.JSONDecodeError):
apitally/starlette.py CHANGED
@@ -62,16 +62,31 @@ class ApitallyMiddleware:
62
62
  response_time = 0.0
63
63
  response_headers = Headers()
64
64
  response_body = b""
65
+ response_size = 0
66
+ response_chunked = False
65
67
  start_time = time.perf_counter()
66
68
 
67
69
  async def send_wrapper(message: Message) -> None:
68
- nonlocal response_time, response_status, response_headers, response_body
70
+ nonlocal \
71
+ response_time, \
72
+ response_status, \
73
+ response_headers, \
74
+ response_body, \
75
+ response_size, \
76
+ response_chunked
69
77
  if message["type"] == "http.response.start":
70
78
  response_time = time.perf_counter() - start_time
71
79
  response_status = message["status"]
72
80
  response_headers = Headers(scope=message)
73
- elif message["type"] == "http.response.body" and response_status == 422:
74
- response_body += message["body"]
81
+ response_chunked = (
82
+ response_headers.get("Transfer-Encoding") == "chunked"
83
+ or "Content-Length" not in response_headers
84
+ )
85
+ elif message["type"] == "http.response.body":
86
+ if response_chunked:
87
+ response_size += len(message.get("body", b""))
88
+ if response_status == 422:
89
+ response_body += message.get("body", b"")
75
90
  await send(message)
76
91
 
77
92
  try:
@@ -83,6 +98,7 @@ class ApitallyMiddleware:
83
98
  response_time=time.perf_counter() - start_time,
84
99
  response_headers=response_headers,
85
100
  response_body=response_body,
101
+ response_size=response_size,
86
102
  exception=e,
87
103
  )
88
104
  raise e from None
@@ -93,6 +109,7 @@ class ApitallyMiddleware:
93
109
  response_time=response_time,
94
110
  response_headers=response_headers,
95
111
  response_body=response_body,
112
+ response_size=response_size,
96
113
  )
97
114
  else:
98
115
  await self.app(scope, receive, send) # pragma: no cover
@@ -104,6 +121,7 @@ class ApitallyMiddleware:
104
121
  response_time: float,
105
122
  response_headers: Headers,
106
123
  response_body: bytes,
124
+ response_size: int = 0,
107
125
  exception: Optional[BaseException] = None,
108
126
  ) -> None:
109
127
  path_template, is_handled_path = self.get_path_template(request)
@@ -118,7 +136,7 @@ class ApitallyMiddleware:
118
136
  status_code=response_status,
119
137
  response_time=response_time,
120
138
  request_size=request.headers.get("Content-Length"),
121
- response_size=response_headers.get("Content-Length"),
139
+ response_size=response_size or response_headers.get("Content-Length"),
122
140
  )
123
141
  if response_status == 422 and response_body and response_headers.get("Content-Type") == "application/json":
124
142
  with contextlib.suppress(json.JSONDecodeError):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apitally
3
- Version: 0.12.0
3
+ Version: 0.12.1
4
4
  Summary: Simple API monitoring & analytics for REST APIs built with FastAPI, Flask, Django, Starlette and Litestar.
5
5
  Home-page: https://apitally.io
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- apitally/__init__.py,sha256=eHjt9DPsMbptabS2yGx9Yhbyzq5hFSUHXb7zc8Q_8-o,23
1
+ apitally/__init__.py,sha256=PAuBI8I6F9Yu_86XjI2yaWn8QmCd9ZvK7tkZLWvEg-Q,23
2
2
  apitally/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  apitally/client/asyncio.py,sha256=Y5sbRLRnJCIJx9VQ2DGgQsYNKGvURV2U1y3VxHuPhgQ,4874
4
4
  apitally/client/base.py,sha256=v4LSOYNIOoeL3KTVyBlXBY5LCXc79Lvu9yK5Y_KILSQ,15442
@@ -10,10 +10,10 @@ apitally/django_ninja.py,sha256=dqQtnz2s8YWYHCwvkK5BjokjvpZJpPNhP0vng4kFtrQ,120
10
10
  apitally/django_rest_framework.py,sha256=dqQtnz2s8YWYHCwvkK5BjokjvpZJpPNhP0vng4kFtrQ,120
11
11
  apitally/fastapi.py,sha256=hEyYZsvIaA3OXZSSFdey5iqeEjfBPHgfNbyX8pLm7GI,123
12
12
  apitally/flask.py,sha256=7TJIoAT91-bR_7gZkL0clDk-Whl-V21hbo4nASaDmB4,6447
13
- apitally/litestar.py,sha256=sQcrHw-JV9AlpnXlrczmaDe0k6tD9PYQsc8nyQul8Ko,8802
13
+ apitally/litestar.py,sha256=O9bSzwJC-dN6ukRqyVNYBhUqxEpzie-bR2bFojcvvMI,9547
14
14
  apitally/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- apitally/starlette.py,sha256=PA_0BTy9aVtrY2_QrWU7Js5vjW1uxZ476rmg95fXq2g,8881
16
- apitally-0.12.0.dist-info/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
17
- apitally-0.12.0.dist-info/METADATA,sha256=gGryZ9u9sLV8mYrcoRhvYK4lQ4bFf9vhbvrCENA6T-I,6994
18
- apitally-0.12.0.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
19
- apitally-0.12.0.dist-info/RECORD,,
15
+ apitally/starlette.py,sha256=qmdcAlypqACd4yL_B_5W0ykpkWJaf1YcCAW1yDxaS0c,9615
16
+ apitally-0.12.1.dist-info/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
17
+ apitally-0.12.1.dist-info/METADATA,sha256=Fibm2KONAkF7Omu-bpxBWvzvhRbjYdtcN9I7h1oVMbg,6994
18
+ apitally-0.12.1.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
19
+ apitally-0.12.1.dist-info/RECORD,,