blipit 0.1.0__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.
blipit/__init__.py ADDED
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional
4
+
5
+ import sentry_sdk
6
+ from sentry_sdk import add_breadcrumb, capture_exception, capture_message, set_tag, set_user
7
+
8
+ DEFAULT_ENDPOINT = "https://in.blipit.io"
9
+
10
+ __all__ = [
11
+ "init",
12
+ "capture_exception",
13
+ "capture_message",
14
+ "capture_security",
15
+ "set_user",
16
+ "set_tag",
17
+ "add_breadcrumb",
18
+ "flush",
19
+ ]
20
+
21
+
22
+ def dsn(key: str, project: int | str, endpoint: str = DEFAULT_ENDPOINT) -> str:
23
+ host = endpoint.split("://", 1)[-1].rstrip("/")
24
+ scheme = "http" if endpoint.startswith("http://") else "https"
25
+ return f"{scheme}://{key}@{host}/{project}"
26
+
27
+
28
+ def init(
29
+ key: str,
30
+ project: int | str,
31
+ environment: Optional[str] = None,
32
+ release: Optional[str] = None,
33
+ traces_sample_rate: float = 0.0,
34
+ endpoint: str = DEFAULT_ENDPOINT,
35
+ **options: Any,
36
+ ) -> None:
37
+ if not key:
38
+ raise ValueError("blipit.init needs the project's public key")
39
+ options.setdefault("send_default_pii", False)
40
+ sentry_sdk.init(
41
+ dsn=dsn(key, project, endpoint),
42
+ environment=environment,
43
+ release=release,
44
+ traces_sample_rate=traces_sample_rate,
45
+ **options,
46
+ )
47
+
48
+
49
+ def capture_security(
50
+ kind: str,
51
+ actor: str,
52
+ outcome: Optional[str] = None,
53
+ actor_id: Optional[str] = None,
54
+ ip: Optional[str] = None,
55
+ user_agent: Optional[str] = None,
56
+ target: Optional[str] = None,
57
+ ) -> None:
58
+ payload = {
59
+ "kind": kind,
60
+ "actor": actor,
61
+ "outcome": outcome,
62
+ "actor_id": actor_id,
63
+ "ip": ip,
64
+ "user_agent": user_agent,
65
+ "target": target,
66
+ }
67
+ with sentry_sdk.new_scope() as scope:
68
+ scope.set_context("security", {k: v for k, v in payload.items() if v is not None})
69
+ scope.set_tag("security.kind", kind)
70
+ level = "warning" if kind in ("login_failed", "login_blocked") else "info"
71
+ capture_message(f"{kind} for {actor}", level=level)
72
+
73
+
74
+ def flush(timeout: float = 2.0) -> None:
75
+ sentry_sdk.flush(timeout)
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.5
2
+ Name: blipit
3
+ Version: 0.1.0
4
+ Summary: Blipit error monitoring for Python: Django, Flask, FastAPI, Celery and scripts. Know your app broke before your users tell you.
5
+ Project-URL: Homepage, https://blipit.io
6
+ Project-URL: Documentation, https://docs.blipit.io/python
7
+ Project-URL: Changelog, https://blipit.io/changelog
8
+ Author-email: Louward Labs <support@blipit.io>
9
+ License-Expression: MIT
10
+ Keywords: blipit,django,error-monitoring,errors,fastapi,flask,logging
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: System :: Monitoring
16
+ Requires-Python: >=3.8
17
+ Requires-Dist: sentry-sdk>=2.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ # blipit
21
+
22
+ Blipit error monitoring for Python. Know your app broke before your users tell you.
23
+
24
+ ## Install
25
+
26
+ ```sh
27
+ pip install blipit
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ Call `init` once at startup, before the app is created. For Django, put it at the top of `settings.py`.
33
+
34
+ ```python
35
+ import blipit
36
+
37
+ blipit.init(key="<public key>", project=<project id>, environment="production", release="myapp@1.4.2")
38
+ ```
39
+
40
+ Both values are on the project's Keys page at app.blipit.io. Unhandled exceptions are reported on their own; Django, Flask, FastAPI, Celery, SQLAlchemy and other integrations are detected automatically.
41
+
42
+ ## Manual capture
43
+
44
+ ```python
45
+ blipit.capture_exception(err)
46
+ blipit.capture_message("cache miss rate above 50%", level="warning")
47
+ blipit.set_user({"id": "42", "email": "ana@example.com"})
48
+ blipit.set_tag("region", "ap-southeast-1")
49
+ ```
50
+
51
+ ## Performance
52
+
53
+ Pass `traces_sample_rate=0.2` to `init` and requests show up on the Performance page.
54
+
55
+ Docs: https://docs.blipit.io/python
@@ -0,0 +1,4 @@
1
+ blipit/__init__.py,sha256=1_nNtoNXVzbtz5QwO2tRm4hGijMoiovkHGxVyDCODko,2034
2
+ blipit-0.1.0.dist-info/METADATA,sha256=YDUEu6TCgDYJjZf6bBT9WKs8SJNvDmxN1e-JpzGIf38,1770
3
+ blipit-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
4
+ blipit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any