errorlens 0.2.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.
errorlens/__init__.py ADDED
@@ -0,0 +1,133 @@
1
+ """ErrorLens Python SDK.
2
+
3
+ Reports errors to a self-hosted ErrorLens server. Event capture and transport
4
+ are provided by the MIT-licensed open-source error SDK this package builds on;
5
+ this module adds ErrorLens defaults (privacy-first, quiet console) and a
6
+ ErrorLens-branded API.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ from typing import Any, Callable, Optional
13
+
14
+ # The underlying library prints setup hints mentioning its own product to the
15
+ # console. ErrorLens users should never see those.
16
+ os.environ.setdefault("SENTRY_AGENT_HINTS", "0")
17
+
18
+ import sentry_sdk as _impl # noqa: E402
19
+ from sentry_sdk import consts as _consts # noqa: E402
20
+
21
+ from ._version import __version__ # noqa: E402
22
+
23
+ SDK_NAME = "errorlens.python"
24
+
25
+ __all__ = [
26
+ "__version__",
27
+ "init",
28
+ "is_enabled",
29
+ "capture_exception",
30
+ "capture_message",
31
+ "capture_event",
32
+ "add_breadcrumb",
33
+ "set_user",
34
+ "set_tag",
35
+ "set_tags",
36
+ "set_context",
37
+ "set_extra",
38
+ "flush",
39
+ "last_event_id",
40
+ "new_scope",
41
+ "isolation_scope",
42
+ ]
43
+
44
+ Event = dict
45
+ Hint = dict
46
+ BeforeSend = Callable[[Event, Hint], Optional[Event]]
47
+
48
+
49
+ def _supported(option: str) -> bool:
50
+ defaults = getattr(_consts, "DEFAULT_OPTIONS", None)
51
+ return defaults is None or option in defaults
52
+
53
+
54
+ def _brand(user_hook: Optional[BeforeSend]) -> BeforeSend:
55
+ """Wraps before_send so stored events identify this SDK as ErrorLens."""
56
+
57
+ def hook(event: Event, hint: Hint) -> Optional[Event]:
58
+ sdk = event.get("sdk") or {}
59
+ sdk["name"] = SDK_NAME
60
+ sdk["version"] = __version__
61
+ # Report our package plus the core library version under a neutral name.
62
+ sdk["packages"] = [
63
+ {"name": "pypi:errorlens", "version": __version__},
64
+ {"name": "pypi:core", "version": getattr(_impl, "VERSION", "")},
65
+ ]
66
+ event["sdk"] = sdk
67
+ return user_hook(event, hint) if user_hook else event
68
+
69
+ return hook
70
+
71
+
72
+ def init(
73
+ dsn: Optional[str] = None,
74
+ *,
75
+ release: Optional[str] = None,
76
+ environment: Optional[str] = None,
77
+ before_send: Optional[BeforeSend] = None,
78
+ **options: Any,
79
+ ) -> None:
80
+ """Start reporting errors to ErrorLens.
81
+
82
+ dsn, release and environment default to the ERRORLENS_DSN,
83
+ ERRORLENS_RELEASE and ERRORLENS_ENVIRONMENT environment variables. With no
84
+ DSN the SDK is a no-op, so it is safe to call in tests and local dev.
85
+
86
+ Any other keyword argument is passed to the underlying client; options it
87
+ does not support are ignored rather than raising.
88
+ """
89
+ opts: dict = {
90
+ "dsn": dsn or os.environ.get("ERRORLENS_DSN") or None,
91
+ "release": release or os.environ.get("ERRORLENS_RELEASE") or None,
92
+ "environment": environment or os.environ.get("ERRORLENS_ENVIRONMENT") or None,
93
+ "before_send": _brand(before_send),
94
+ # Privacy-first defaults (callers may override).
95
+ "send_default_pii": False,
96
+ # Performance tracing is opt-in: pass traces_sample_rate to enable it.
97
+ "traces_sample_rate": None,
98
+ }
99
+ opts.update(options)
100
+ opts = {k: v for k, v in opts.items() if _supported(k)}
101
+ _impl.init(**opts)
102
+
103
+
104
+ def is_enabled() -> bool:
105
+ """True if init() was called with a DSN."""
106
+ client = _impl.get_client()
107
+ return bool(client and client.is_active() and client.dsn)
108
+
109
+
110
+ def _export(name: str):
111
+ fn = getattr(_impl, name, None)
112
+ if fn is None:
113
+
114
+ def missing(*_a: Any, **_k: Any) -> None:
115
+ raise NotImplementedError(f"errorlens.{name} is not available with the installed core library")
116
+
117
+ return missing
118
+ return fn
119
+
120
+
121
+ capture_exception = _export("capture_exception")
122
+ capture_message = _export("capture_message")
123
+ capture_event = _export("capture_event")
124
+ add_breadcrumb = _export("add_breadcrumb")
125
+ set_user = _export("set_user")
126
+ set_tag = _export("set_tag")
127
+ set_tags = _export("set_tags")
128
+ set_context = _export("set_context")
129
+ set_extra = _export("set_extra")
130
+ flush = _export("flush")
131
+ last_event_id = _export("last_event_id")
132
+ new_scope = _export("new_scope")
133
+ isolation_scope = _export("isolation_scope")
errorlens/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.5
2
+ Name: errorlens
3
+ Version: 0.2.0
4
+ Summary: Python SDK for ErrorLens, the open-source, self-hosted error tracker.
5
+ Project-URL: Homepage, https://errorlens.io
6
+ Project-URL: Documentation, https://errorlens.io/docs/python/
7
+ Project-URL: Issues, https://github.com/errorlens-io/errorlens/issues
8
+ Project-URL: Source, https://github.com/errorlens-io/errorlens
9
+ Author: ErrorLens contributors
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: error tracking,errorlens,exceptions,monitoring,self-hosted
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Bug Tracking
17
+ Requires-Python: >=3.9
18
+ Requires-Dist: sentry-sdk<4,>=2.0
19
+ Description-Content-Type: text/markdown
20
+
21
+ # errorlens — Python SDK for ErrorLens
22
+
23
+ Report errors from Python apps to your own [ErrorLens](https://errorlens.io) server.
24
+
25
+ ```bash
26
+ pip install errorlens
27
+ ```
28
+
29
+ ```python
30
+ import errorlens
31
+
32
+ errorlens.init(
33
+ dsn="https://<key>@errors.example.com/1", # from your ErrorLens project page
34
+ release="my-app@1.0.0",
35
+ environment="production",
36
+ )
37
+ ```
38
+
39
+ Unhandled exceptions are reported automatically. You can also report manually:
40
+
41
+ ```python
42
+ try:
43
+ risky()
44
+ except Exception:
45
+ errorlens.capture_exception()
46
+
47
+ errorlens.capture_message("Payment provider slow", level="warning")
48
+ errorlens.set_user({"id": "42"})
49
+ errorlens.set_tag("region", "eu-west")
50
+ ```
51
+
52
+ Configuration can also come from environment variables: `ERRORLENS_DSN`,
53
+ `ERRORLENS_RELEASE`, `ERRORLENS_ENVIRONMENT`.
54
+
55
+ Privacy defaults: personal data (IP addresses, cookies, request bodies) is **not** sent unless
56
+ you pass `send_default_pii=True`, and your ErrorLens server scrubs secrets again before storage.
57
+
58
+ Django, Flask, FastAPI, Celery and other frameworks are detected automatically.
59
+
60
+ License: MIT.
@@ -0,0 +1,6 @@
1
+ errorlens/__init__.py,sha256=asLFP-VAHW4OOcha34q67372R0990WzH8y2J8Tef3ig,4081
2
+ errorlens/_version.py,sha256=Zn1KFblwuFHiDRdRAiRnDBRkbPttWh44jKa5zG2ov0E,22
3
+ errorlens-0.2.0.dist-info/METADATA,sha256=4Hqo6J1BlB8o1W4KmA56BXm9tcqwP_OSZ8un_W1RbNU,1876
4
+ errorlens-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ errorlens-0.2.0.dist-info/licenses/LICENSE,sha256=COMlyP1crEQUTiTOwRvBOopoH6StYIg0UyLzC5Ff-_w,1079
6
+ errorlens-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ErrorLens contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.