apitally 0.19.0__py3-none-any.whl → 0.19.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/client/sentry.py CHANGED
@@ -6,17 +6,22 @@ from typing import Callable, Set
6
6
  _tasks: Set[asyncio.Task] = set()
7
7
 
8
8
 
9
- def get_sentry_event_id_async(cb: Callable[[str], None]) -> None:
9
+ def get_sentry_event_id_async(cb: Callable[[str], None], raise_on_error: bool = False) -> None:
10
10
  try:
11
- from sentry_sdk.hub import Hub
11
+ import sentry_sdk
12
12
  from sentry_sdk.scope import Scope
13
13
  except ImportError:
14
+ if raise_on_error:
15
+ raise
14
16
  return # pragma: no cover
15
17
  if not hasattr(Scope, "get_isolation_scope") or not hasattr(Scope, "_last_event_id"):
16
- # sentry-sdk < 2.2.0 is not supported
18
+ if raise_on_error:
19
+ raise RuntimeError("sentry-sdk < 2.2.0 is not supported")
17
20
  return # pragma: no cover
18
- if Hub.current.client is None:
19
- return # sentry-sdk not initialized
21
+ if not sentry_sdk.is_initialized():
22
+ if raise_on_error:
23
+ raise RuntimeError("sentry-sdk not initialized")
24
+ return
20
25
 
21
26
  scope = Scope.get_isolation_scope()
22
27
  if event_id := scope._last_event_id:
apitally/fastapi.py CHANGED
@@ -1,4 +1,4 @@
1
- from apitally.starlette import ApitallyConsumer, ApitallyMiddleware, RequestLoggingConfig
1
+ from apitally.starlette import ApitallyConsumer, ApitallyMiddleware, RequestLoggingConfig, set_consumer
2
2
 
3
3
 
4
- __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig"]
4
+ __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig", "set_consumer"]
apitally/flask.py CHANGED
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
28
28
  from werkzeug.routing.map import Map
29
29
 
30
30
 
31
- __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig"]
31
+ __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig", "set_consumer"]
32
32
 
33
33
 
34
34
  class ApitallyMiddleware:
@@ -216,6 +216,10 @@ class ApitallyMiddleware:
216
216
  return None
217
217
 
218
218
 
219
+ def set_consumer(identifier: str, name: Optional[str] = None, group: Optional[str] = None) -> None:
220
+ g.apitally_consumer = ApitallyConsumer(identifier, name=name, group=group)
221
+
222
+
219
223
  def _get_startup_data(
220
224
  app: Flask, app_version: Optional[str] = None, openapi_url: Optional[str] = None
221
225
  ) -> Dict[str, Any]:
apitally/litestar.py CHANGED
@@ -24,7 +24,7 @@ from apitally.client.request_logging import (
24
24
  from apitally.common import get_versions, parse_int, try_json_loads
25
25
 
26
26
 
27
- __all__ = ["ApitallyPlugin", "ApitallyConsumer", "RequestLoggingConfig"]
27
+ __all__ = ["ApitallyPlugin", "ApitallyConsumer", "RequestLoggingConfig", "set_consumer"]
28
28
 
29
29
 
30
30
  class ApitallyPlugin(InitPluginProtocol):
@@ -287,6 +287,10 @@ class ApitallyPlugin(InitPluginProtocol):
287
287
  return None
288
288
 
289
289
 
290
+ def set_consumer(request: Request, identifier: str, name: Optional[str] = None, group: Optional[str] = None) -> None:
291
+ request.state.apitally_consumer = ApitallyConsumer(identifier, name=name, group=group)
292
+
293
+
290
294
  def _get_openapi(app: Litestar) -> str:
291
295
  schema = app.openapi_schema.to_schema()
292
296
  return json.dumps(schema)
apitally/starlette.py CHANGED
@@ -25,7 +25,7 @@ from apitally.client.request_logging import (
25
25
  from apitally.common import get_versions, parse_int, try_json_loads
26
26
 
27
27
 
28
- __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig"]
28
+ __all__ = ["ApitallyMiddleware", "ApitallyConsumer", "RequestLoggingConfig", "set_consumer"]
29
29
 
30
30
 
31
31
  class ApitallyMiddleware:
@@ -268,6 +268,10 @@ class ApitallyMiddleware:
268
268
  return None
269
269
 
270
270
 
271
+ def set_consumer(request: Request, identifier: str, name: Optional[str] = None, group: Optional[str] = None) -> None:
272
+ request.state.apitally_consumer = ApitallyConsumer(identifier, name=name, group=group)
273
+
274
+
271
275
  def _get_startup_data(
272
276
  app: ASGIApp, app_version: Optional[str] = None, openapi_url: Optional[str] = None
273
277
  ) -> Dict[str, Any]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apitally
3
- Version: 0.19.0
3
+ Version: 0.19.1
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
@@ -4,11 +4,11 @@ apitally/common.py,sha256=azDxepViH0QW0MuufTHxeSQyLGzCkocAX_KPziWTx8A,1605
4
4
  apitally/django.py,sha256=7eSh1tzuu0wRl9PxJgXMBSz9DfyohCDIqd4ecQTOJ1M,18499
5
5
  apitally/django_ninja.py,sha256=-CmrwFFRv7thFOUK_OrOSouhHL9bm5sIBNIQlpyE_2c,166
6
6
  apitally/django_rest_framework.py,sha256=-CmrwFFRv7thFOUK_OrOSouhHL9bm5sIBNIQlpyE_2c,166
7
- apitally/fastapi.py,sha256=IfKfgsmIY8_AtnuMTW2sW4qnkya61CAE2vBoIpcc9tk,169
8
- apitally/flask.py,sha256=OoCEnjtnD51GUGq-adK80ebuiLj-5HXubxffCv5XTCM,9622
9
- apitally/litestar.py,sha256=mHoMqBO_gyoopeHljY8e8GTcV29UDf3uhQMxY3GeNpA,13451
7
+ apitally/fastapi.py,sha256=813dGFl2eOSSYOYwuubFQYvpRikV3shu7bLR2TlwUC8,199
8
+ apitally/flask.py,sha256=sqcsVmbfqpVSN409xDF8DeGOSNkWHI4SoyTFxNfWJ4w,9819
9
+ apitally/litestar.py,sha256=fmcWNmvGvrjGG6J_q5lqB_qJpTk6PXFK9jam6bTWU8U,13678
10
10
  apitally/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- apitally/starlette.py,sha256=Ep7n_yAqoleFpuLk43kMONiFJVRsFsu-G2_TIjfiCHQ,13878
11
+ apitally/starlette.py,sha256=PnEwplG7i0qJpfEWKdJxGCIioLFp4kQfa-5Y6NWGSSg,14105
12
12
  apitally/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  apitally/client/client_asyncio.py,sha256=rTsH5wlLHK3RmyIuEiT6vzjquU-l2OPC34JnC2U6uYw,6658
14
14
  apitally/client/client_base.py,sha256=DvivGeHd3dyOASRvkIo44Zh8RzdBMfH8_rROa2lFbgw,3799
@@ -17,10 +17,10 @@ apitally/client/consumers.py,sha256=w_AFQhVgdtJVt7pVySBvSZwQg-2JVqmD2JQtVBoMkus,
17
17
  apitally/client/logging.py,sha256=QMsKIIAFo92PNBUleeTgsrsQa7SEal-oJa1oOHUr1wI,507
18
18
  apitally/client/request_logging.py,sha256=yCF_CH8isp3gpQRVgakk6DNV60mtPZWG6z45pUNACOM,17644
19
19
  apitally/client/requests.py,sha256=SDptGOg9XvaEKFj2o3oxJz-JAuZzUrqpHnbOQixf99o,3794
20
- apitally/client/sentry.py,sha256=qMjHdI0V7c50ruo1WjmjWc8g6oGDv724vSCvcuZ8G9k,1188
20
+ apitally/client/sentry.py,sha256=dXW2zf-wexYSp4CJBsFFRKz9jWkPBy0ftqIk0o5Hkq8,1364
21
21
  apitally/client/server_errors.py,sha256=4B2BKDFoIpoWc55UVH6AIdYSgzj6zxCdMNUW77JjhZw,3423
22
22
  apitally/client/validation_errors.py,sha256=6G8WYWFgJs9VH9swvkPXJGuOJgymj5ooWA9OwjUTbuM,1964
23
- apitally-0.19.0.dist-info/METADATA,sha256=9hbiC_z4DINCao5gg0F0Lqd9NVR8hZqNnnjpXkg9lnI,9316
24
- apitally-0.19.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
- apitally-0.19.0.dist-info/licenses/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
26
- apitally-0.19.0.dist-info/RECORD,,
23
+ apitally-0.19.1.dist-info/METADATA,sha256=QE1kA2cHRaEPmxm3feYkfbeowkZMGnuAu5plkvfXDz0,9316
24
+ apitally-0.19.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ apitally-0.19.1.dist-info/licenses/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
26
+ apitally-0.19.1.dist-info/RECORD,,