apitally 0.16.0__py3-none-any.whl → 0.16.2__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/blacksheep.py +5 -10
- apitally/client/client_asyncio.py +1 -7
- apitally/client/client_threading.py +1 -3
- apitally/django.py +1 -1
- apitally/flask.py +1 -1
- apitally/starlette.py +10 -17
- {apitally-0.16.0.dist-info → apitally-0.16.2.dist-info}/METADATA +1 -1
- {apitally-0.16.0.dist-info → apitally-0.16.2.dist-info}/RECORD +10 -10
- {apitally-0.16.0.dist-info → apitally-0.16.2.dist-info}/WHEEL +0 -0
- {apitally-0.16.0.dist-info → apitally-0.16.2.dist-info}/licenses/LICENSE +0 -0
apitally/blacksheep.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import asyncio
|
2
1
|
import time
|
3
2
|
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union
|
4
3
|
|
@@ -60,15 +59,14 @@ class ApitallyMiddleware:
|
|
60
59
|
identify_consumer_callback: Optional[Callable[[Request], Union[str, ApitallyConsumer, None]]] = None,
|
61
60
|
) -> None:
|
62
61
|
self.app = app
|
62
|
+
self.app_version = app_version
|
63
63
|
self.identify_consumer_callback = identify_consumer_callback
|
64
64
|
self.client = ApitallyClient(
|
65
65
|
client_id=client_id,
|
66
66
|
env=env,
|
67
67
|
request_logging_config=request_logging_config,
|
68
68
|
)
|
69
|
-
self.
|
70
|
-
self._delayed_set_startup_data_task: Optional[asyncio.Task] = None
|
71
|
-
self.delayed_set_startup_data(app_version)
|
69
|
+
self.app.on_start += self.after_start
|
72
70
|
self.app.on_stop += self.on_stop
|
73
71
|
|
74
72
|
self.capture_request_body = (
|
@@ -78,13 +76,10 @@ class ApitallyMiddleware:
|
|
78
76
|
self.client.request_logger.config.enabled and self.client.request_logger.config.log_response_body
|
79
77
|
)
|
80
78
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
async def _delayed_set_startup_data(self, app_version: Optional[str] = None) -> None:
|
85
|
-
await asyncio.sleep(1.0) # Short delay to allow app routes to be registered first
|
86
|
-
data = _get_startup_data(self.app, app_version=app_version)
|
79
|
+
async def after_start(self, application: Application) -> None:
|
80
|
+
data = _get_startup_data(application, app_version=self.app_version)
|
87
81
|
self.client.set_startup_data(data)
|
82
|
+
self.client.start_sync_loop()
|
88
83
|
|
89
84
|
async def on_stop(self, application: Application) -> None:
|
90
85
|
await self.client.handle_shutdown()
|
@@ -41,7 +41,6 @@ class ApitallyClient(ApitallyClientBase):
|
|
41
41
|
self._stop_sync_loop = False
|
42
42
|
self._sync_loop_task: Optional[asyncio.Task] = None
|
43
43
|
self._sync_data_queue: asyncio.Queue[Dict[str, Any]] = asyncio.Queue()
|
44
|
-
self._set_startup_data_task: Optional[asyncio.Task] = None
|
45
44
|
|
46
45
|
def get_http_client(self) -> httpx.AsyncClient:
|
47
46
|
if httpx.__version__ >= "0.26.0":
|
@@ -67,7 +66,7 @@ class ApitallyClient(ApitallyClientBase):
|
|
67
66
|
try:
|
68
67
|
async with self.get_http_client() as client:
|
69
68
|
tasks = [self.send_sync_data(client), self.send_log_data(client)]
|
70
|
-
if not self._startup_data_sent
|
69
|
+
if not self._startup_data_sent:
|
71
70
|
tasks.append(self.send_startup_data(client))
|
72
71
|
await asyncio.gather(*tasks)
|
73
72
|
last_sync_time = now
|
@@ -92,11 +91,6 @@ class ApitallyClient(ApitallyClientBase):
|
|
92
91
|
def set_startup_data(self, data: Dict[str, Any]) -> None:
|
93
92
|
self._startup_data_sent = False
|
94
93
|
self._startup_data = self.add_uuids_to_data(data)
|
95
|
-
self._set_startup_data_task = asyncio.create_task(self._set_startup_data())
|
96
|
-
|
97
|
-
async def _set_startup_data(self) -> None:
|
98
|
-
async with self.get_http_client() as client:
|
99
|
-
await self.send_startup_data(client)
|
100
94
|
|
101
95
|
async def send_startup_data(self, client: httpx.AsyncClient) -> None:
|
102
96
|
if self._startup_data is not None:
|
@@ -80,7 +80,7 @@ class ApitallyClient(ApitallyClientBase):
|
|
80
80
|
if (now - last_sync_time) >= self.sync_interval:
|
81
81
|
try:
|
82
82
|
with requests.Session() as session:
|
83
|
-
if not self._startup_data_sent
|
83
|
+
if not self._startup_data_sent:
|
84
84
|
self.send_startup_data(session)
|
85
85
|
self.send_sync_data(session)
|
86
86
|
self.send_log_data(session)
|
@@ -105,8 +105,6 @@ class ApitallyClient(ApitallyClientBase):
|
|
105
105
|
def set_startup_data(self, data: Dict[str, Any]) -> None:
|
106
106
|
self._startup_data_sent = False
|
107
107
|
self._startup_data = self.add_uuids_to_data(data)
|
108
|
-
with requests.Session() as session:
|
109
|
-
self.send_startup_data(session)
|
110
108
|
|
111
109
|
def send_startup_data(self, session: requests.Session) -> None:
|
112
110
|
if self._startup_data is not None:
|
apitally/django.py
CHANGED
@@ -75,13 +75,13 @@ class ApitallyMiddleware:
|
|
75
75
|
request_logging_config=self.config.request_logging_config,
|
76
76
|
proxy=self.config.proxy,
|
77
77
|
)
|
78
|
-
self.client.start_sync_loop()
|
79
78
|
self.client.set_startup_data(
|
80
79
|
_get_startup_data(
|
81
80
|
app_version=self.config.app_version,
|
82
81
|
urlconfs=self.config.urlconfs,
|
83
82
|
)
|
84
83
|
)
|
84
|
+
self.client.start_sync_loop()
|
85
85
|
|
86
86
|
self.capture_request_body = (
|
87
87
|
self.client.request_logger.config.enabled and self.client.request_logger.config.log_request_body
|
apitally/flask.py
CHANGED
@@ -51,7 +51,6 @@ class ApitallyMiddleware:
|
|
51
51
|
request_logging_config=request_logging_config,
|
52
52
|
proxy=proxy,
|
53
53
|
)
|
54
|
-
self.client.start_sync_loop()
|
55
54
|
self.delayed_set_startup_data(app_version, openapi_url)
|
56
55
|
|
57
56
|
self.capture_request_body = (
|
@@ -73,6 +72,7 @@ class ApitallyMiddleware:
|
|
73
72
|
def _delayed_set_startup_data(self, app_version: Optional[str] = None, openapi_url: Optional[str] = None) -> None:
|
74
73
|
data = _get_startup_data(self.app, app_version, openapi_url)
|
75
74
|
self.client.set_startup_data(data)
|
75
|
+
self.client.start_sync_loop()
|
76
76
|
|
77
77
|
def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]:
|
78
78
|
if not self.client.enabled:
|
apitally/starlette.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
import asyncio
|
4
3
|
import time
|
5
4
|
from typing import Any, Callable, Dict, List, Optional, Union
|
6
5
|
from warnings import warn
|
@@ -40,6 +39,8 @@ class ApitallyMiddleware:
|
|
40
39
|
proxy: Optional[Union[str, Proxy]] = None,
|
41
40
|
) -> None:
|
42
41
|
self.app = app
|
42
|
+
self.app_version = app_version
|
43
|
+
self.openapi_url = openapi_url
|
43
44
|
self.identify_consumer_callback = identify_consumer_callback
|
44
45
|
self.client = ApitallyClient(
|
45
46
|
client_id=client_id,
|
@@ -47,10 +48,6 @@ class ApitallyMiddleware:
|
|
47
48
|
request_logging_config=request_logging_config,
|
48
49
|
proxy=proxy,
|
49
50
|
)
|
50
|
-
self.client.start_sync_loop()
|
51
|
-
self._delayed_set_startup_data_task: Optional[asyncio.Task] = None
|
52
|
-
self.delayed_set_startup_data(app_version, openapi_url)
|
53
|
-
_register_shutdown_handler(app, self.client.handle_shutdown)
|
54
51
|
|
55
52
|
self.capture_request_body = (
|
56
53
|
self.client.request_logger.config.enabled and self.client.request_logger.config.log_request_body
|
@@ -59,17 +56,13 @@ class ApitallyMiddleware:
|
|
59
56
|
self.client.request_logger.config.enabled and self.client.request_logger.config.log_response_body
|
60
57
|
)
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
self._delayed_set_startup_data(app_version, openapi_url)
|
65
|
-
)
|
59
|
+
_register_event_handler(app, "startup", self.on_startup)
|
60
|
+
_register_event_handler(app, "shutdown", self.client.handle_shutdown)
|
66
61
|
|
67
|
-
|
68
|
-
self, app_version
|
69
|
-
) -> None:
|
70
|
-
await asyncio.sleep(1.0) # Short delay to allow app routes to be registered first
|
71
|
-
data = _get_startup_data(self.app, app_version, openapi_url)
|
62
|
+
def on_startup(self) -> None:
|
63
|
+
data = _get_startup_data(self.app, app_version=self.app_version, openapi_url=self.openapi_url)
|
72
64
|
self.client.set_startup_data(data)
|
65
|
+
self.client.start_sync_loop()
|
73
66
|
|
74
67
|
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
75
68
|
if self.client.enabled and scope["type"] == "http" and scope["method"] != "OPTIONS":
|
@@ -296,8 +289,8 @@ def _get_routes(app: Union[ASGIApp, Router]) -> List[BaseRoute]:
|
|
296
289
|
return [] # pragma: no cover
|
297
290
|
|
298
291
|
|
299
|
-
def
|
292
|
+
def _register_event_handler(app: Union[ASGIApp, Router], event: str, handler: Callable[[], Any]) -> None:
|
300
293
|
if isinstance(app, Router):
|
301
|
-
app.add_event_handler(
|
294
|
+
app.add_event_handler(event, handler)
|
302
295
|
elif hasattr(app, "app"):
|
303
|
-
|
296
|
+
_register_event_handler(app.app, event, handler)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: apitally
|
3
|
-
Version: 0.16.
|
3
|
+
Version: 0.16.2
|
4
4
|
Summary: Simple API monitoring & analytics for REST APIs built with FastAPI, Flask, Django, Starlette, Litestar and BlackSheep.
|
5
5
|
Project-URL: Homepage, https://apitally.io
|
6
6
|
Project-URL: Documentation, https://docs.apitally.io
|
@@ -1,18 +1,18 @@
|
|
1
1
|
apitally/__init__.py,sha256=ShXQBVjyiSOHxoQJS2BvNG395W4KZfqMxZWBAR0MZrE,22
|
2
|
-
apitally/blacksheep.py,sha256=
|
2
|
+
apitally/blacksheep.py,sha256=KvcPFeiwQgWZmRglbm8SLaN6_WRs5kZ3SymB1IuLR-A,9616
|
3
3
|
apitally/common.py,sha256=azDxepViH0QW0MuufTHxeSQyLGzCkocAX_KPziWTx8A,1605
|
4
|
-
apitally/django.py,sha256=
|
4
|
+
apitally/django.py,sha256=f_k7yYlvvvhJMR53NcXCfmlLxLX3CeLO9ephF4bzKbo,16892
|
5
5
|
apitally/django_ninja.py,sha256=-CmrwFFRv7thFOUK_OrOSouhHL9bm5sIBNIQlpyE_2c,166
|
6
6
|
apitally/django_rest_framework.py,sha256=-CmrwFFRv7thFOUK_OrOSouhHL9bm5sIBNIQlpyE_2c,166
|
7
7
|
apitally/fastapi.py,sha256=IfKfgsmIY8_AtnuMTW2sW4qnkya61CAE2vBoIpcc9tk,169
|
8
|
-
apitally/flask.py,sha256=
|
8
|
+
apitally/flask.py,sha256=OoCEnjtnD51GUGq-adK80ebuiLj-5HXubxffCv5XTCM,9622
|
9
9
|
apitally/litestar.py,sha256=mHoMqBO_gyoopeHljY8e8GTcV29UDf3uhQMxY3GeNpA,13451
|
10
10
|
apitally/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
apitally/starlette.py,sha256=
|
11
|
+
apitally/starlette.py,sha256=g6YmC186uG6Lc9-Gx3Pp4ke-jn8IeKK0nFLBGDnWYv0,12771
|
12
12
|
apitally/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
apitally/client/client_asyncio.py,sha256=
|
13
|
+
apitally/client/client_asyncio.py,sha256=rTsH5wlLHK3RmyIuEiT6vzjquU-l2OPC34JnC2U6uYw,6658
|
14
14
|
apitally/client/client_base.py,sha256=DvivGeHd3dyOASRvkIo44Zh8RzdBMfH8_rROa2lFbgw,3799
|
15
|
-
apitally/client/client_threading.py,sha256=
|
15
|
+
apitally/client/client_threading.py,sha256=sxMRcxRgk1SxJjSq-qpIcDVmD3Q7Kv4CVT5zEUVt0KM,7257
|
16
16
|
apitally/client/consumers.py,sha256=w_AFQhVgdtJVt7pVySBvSZwQg-2JVqmD2JQtVBoMkus,2626
|
17
17
|
apitally/client/logging.py,sha256=QMsKIIAFo92PNBUleeTgsrsQa7SEal-oJa1oOHUr1wI,507
|
18
18
|
apitally/client/request_logging.py,sha256=SMvQd3WDolnb8u9rHVh2_OgXwFjL2jLZt-GpZNQ1XGk,14115
|
@@ -20,7 +20,7 @@ apitally/client/requests.py,sha256=SDptGOg9XvaEKFj2o3oxJz-JAuZzUrqpHnbOQixf99o,3
|
|
20
20
|
apitally/client/sentry.py,sha256=qMjHdI0V7c50ruo1WjmjWc8g6oGDv724vSCvcuZ8G9k,1188
|
21
21
|
apitally/client/server_errors.py,sha256=4B2BKDFoIpoWc55UVH6AIdYSgzj6zxCdMNUW77JjhZw,3423
|
22
22
|
apitally/client/validation_errors.py,sha256=6G8WYWFgJs9VH9swvkPXJGuOJgymj5ooWA9OwjUTbuM,1964
|
23
|
-
apitally-0.16.
|
24
|
-
apitally-0.16.
|
25
|
-
apitally-0.16.
|
26
|
-
apitally-0.16.
|
23
|
+
apitally-0.16.2.dist-info/METADATA,sha256=Lycf-s6pDP5lO9B8-pRqcDfHZcJTFZQ--wSuquoDZn0,9321
|
24
|
+
apitally-0.16.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
25
|
+
apitally-0.16.2.dist-info/licenses/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
|
26
|
+
apitally-0.16.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|