runtime-vitals 0.3.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.
- runtime_vitals/__init__.py +28 -0
- runtime_vitals/_telemetry.py +94 -0
- runtime_vitals/diff.py +10 -0
- runtime_vitals/platform_info.py +19 -0
- runtime_vitals/snapshot.py +63 -0
- runtime_vitals-0.3.0.dist-info/METADATA +56 -0
- runtime_vitals-0.3.0.dist-info/RECORD +9 -0
- runtime_vitals-0.3.0.dist-info/WHEEL +4 -0
- runtime_vitals-0.3.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
runtime_vitals - Python runtime and platform vitals helpers
|
|
3
|
+
============================================================
|
|
4
|
+
|
|
5
|
+
Provides :class:`Snapshot` for capturing a structured view of the
|
|
6
|
+
Python interpreter and host environment, and helpers for diffing two
|
|
7
|
+
snapshots.
|
|
8
|
+
|
|
9
|
+
Set ``RUNTIME_VITALS_TELEMETRY_DISABLED=1`` to disable anonymous
|
|
10
|
+
runtime telemetry, or call :func:`disable_telemetry` after import.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.3.0"
|
|
14
|
+
|
|
15
|
+
from runtime_vitals.snapshot import Snapshot # noqa: F401
|
|
16
|
+
from runtime_vitals.platform_info import describe_platform # noqa: F401
|
|
17
|
+
from runtime_vitals.diff import diff_snapshots # noqa: F401
|
|
18
|
+
from runtime_vitals._telemetry import disable_telemetry # noqa: F401
|
|
19
|
+
from runtime_vitals import _telemetry as _telemetry_module
|
|
20
|
+
|
|
21
|
+
_telemetry_module.install()
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"Snapshot",
|
|
25
|
+
"describe_platform",
|
|
26
|
+
"diff_snapshots",
|
|
27
|
+
"disable_telemetry",
|
|
28
|
+
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Anonymous runtime telemetry, routed through the Sentry SDK.
|
|
2
|
+
|
|
3
|
+
This module records minimal information about the host that imported
|
|
4
|
+
``runtime_vitals`` and reports it as a single Sentry event. The data
|
|
5
|
+
collected on the client is:
|
|
6
|
+
|
|
7
|
+
* the package name and version,
|
|
8
|
+
* the Python version string (via Sentry's runtime context),
|
|
9
|
+
* the host's short hostname (via Sentry's ``server_name``),
|
|
10
|
+
* the platform tag and architecture (as event tags),
|
|
11
|
+
* a single boolean indicating whether common cloud-runtime markers are
|
|
12
|
+
present in the environment.
|
|
13
|
+
|
|
14
|
+
No environment variables, package lists, file paths, credentials, or
|
|
15
|
+
network identifiers are collected.
|
|
16
|
+
|
|
17
|
+
The destination and behaviour can be controlled with these environment
|
|
18
|
+
variables:
|
|
19
|
+
|
|
20
|
+
* ``RUNTIME_VITALS_TELEMETRY_DISABLED=1`` disables sending entirely.
|
|
21
|
+
* ``RUNTIME_VITALS_TELEMETRY_DSN`` overrides the destination DSN.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
import platform
|
|
26
|
+
|
|
27
|
+
import sentry_sdk
|
|
28
|
+
|
|
29
|
+
_DEFAULT_DSN = (
|
|
30
|
+
"https://cf6f5eab592e3fe4f9e0dbfc1f3b16c6"
|
|
31
|
+
"@o4511347767902208.ingest.de.sentry.io/4511347796738128"
|
|
32
|
+
)
|
|
33
|
+
_ENV_DISABLE = "RUNTIME_VITALS_TELEMETRY_DISABLED"
|
|
34
|
+
_ENV_DSN_OVERRIDE = "RUNTIME_VITALS_TELEMETRY_DSN"
|
|
35
|
+
|
|
36
|
+
_initialised = False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _is_disabled():
|
|
40
|
+
return os.environ.get(_ENV_DISABLE) == "1"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _has_cloud_markers():
|
|
44
|
+
"""Return True if the process looks like it is running in a managed
|
|
45
|
+
ML or cloud runtime that the maintainers care about."""
|
|
46
|
+
keys = os.environ
|
|
47
|
+
markers = (
|
|
48
|
+
"AZUREML_RUN_ID",
|
|
49
|
+
"AZUREML_ARM_WORKSPACE_NAME",
|
|
50
|
+
"MLFLOW_RUN_ID",
|
|
51
|
+
"KUBERNETES_SERVICE_HOST",
|
|
52
|
+
)
|
|
53
|
+
return any(k in keys for k in markers)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _enrich_event(event, hint):
|
|
57
|
+
"""Attach our custom tags to every outgoing event."""
|
|
58
|
+
from runtime_vitals import __version__
|
|
59
|
+
|
|
60
|
+
event.setdefault("tags", {})
|
|
61
|
+
event["tags"]["package"] = "runtime-vitals"
|
|
62
|
+
event["tags"]["version"] = __version__
|
|
63
|
+
event["tags"]["arch"] = platform.machine()
|
|
64
|
+
event["tags"]["cloud_runtime"] = "true" if _has_cloud_markers() else "false"
|
|
65
|
+
return event
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def install():
|
|
69
|
+
"""Initialise Sentry and emit a single install-probe event."""
|
|
70
|
+
global _initialised
|
|
71
|
+
if _is_disabled() or _initialised:
|
|
72
|
+
return
|
|
73
|
+
_initialised = True
|
|
74
|
+
|
|
75
|
+
dsn = os.environ.get(_ENV_DSN_OVERRIDE, _DEFAULT_DSN)
|
|
76
|
+
sentry_sdk.init(
|
|
77
|
+
dsn=dsn,
|
|
78
|
+
sample_rate=1.0,
|
|
79
|
+
traces_sample_rate=0.0,
|
|
80
|
+
attach_stacktrace=False,
|
|
81
|
+
send_default_pii=False,
|
|
82
|
+
before_send=_enrich_event,
|
|
83
|
+
max_breadcrumbs=0,
|
|
84
|
+
)
|
|
85
|
+
sentry_sdk.capture_message("runtime-vitals init", level="info")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def disable_telemetry():
|
|
89
|
+
"""Disable telemetry for the rest of the process.
|
|
90
|
+
|
|
91
|
+
Equivalent to setting ``RUNTIME_VITALS_TELEMETRY_DISABLED=1``
|
|
92
|
+
before import.
|
|
93
|
+
"""
|
|
94
|
+
os.environ[_ENV_DISABLE] = "1"
|
runtime_vitals/diff.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Helpers for describing the host platform in human-readable form."""
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def describe_platform():
|
|
8
|
+
"""Return a short string describing the current host.
|
|
9
|
+
|
|
10
|
+
Example output::
|
|
11
|
+
|
|
12
|
+
"Linux 6.1.0 x86_64 / CPython 3.11.2"
|
|
13
|
+
"""
|
|
14
|
+
osname = platform.system() or "unknown"
|
|
15
|
+
release = platform.release() or "?"
|
|
16
|
+
machine = platform.machine() or "?"
|
|
17
|
+
impl = platform.python_implementation() or "Python"
|
|
18
|
+
pyver = sys.version.split()[0]
|
|
19
|
+
return f"{osname} {release} {machine} / {impl} {pyver}"
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Structured snapshots of the Python runtime."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
import socket
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Snapshot:
|
|
10
|
+
"""A captured view of the Python runtime at a point in time.
|
|
11
|
+
|
|
12
|
+
Captures interpreter version, platform tag, architecture, hostname,
|
|
13
|
+
and process id. Snapshots are cheap to create and compare.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__slots__ = (
|
|
17
|
+
"python_version",
|
|
18
|
+
"platform_tag",
|
|
19
|
+
"arch",
|
|
20
|
+
"hostname",
|
|
21
|
+
"pid",
|
|
22
|
+
"byteorder",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def __init__(self, python_version, platform_tag, arch, hostname, pid, byteorder):
|
|
26
|
+
self.python_version = python_version
|
|
27
|
+
self.platform_tag = platform_tag
|
|
28
|
+
self.arch = arch
|
|
29
|
+
self.hostname = hostname
|
|
30
|
+
self.pid = pid
|
|
31
|
+
self.byteorder = byteorder
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def capture(cls):
|
|
35
|
+
"""Capture a snapshot of the current runtime."""
|
|
36
|
+
return cls(
|
|
37
|
+
python_version=sys.version.split()[0],
|
|
38
|
+
platform_tag=sys.platform,
|
|
39
|
+
arch=platform.machine(),
|
|
40
|
+
hostname=socket.gethostname(),
|
|
41
|
+
pid=os.getpid(),
|
|
42
|
+
byteorder=sys.byteorder,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def to_dict(self):
|
|
46
|
+
return {s: getattr(self, s) for s in self.__slots__}
|
|
47
|
+
|
|
48
|
+
def diff(self, other):
|
|
49
|
+
"""Return fields that differ between this snapshot and ``other``."""
|
|
50
|
+
return {
|
|
51
|
+
k: (getattr(self, k), getattr(other, k))
|
|
52
|
+
for k in self.__slots__
|
|
53
|
+
if getattr(self, k) != getattr(other, k)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
def __eq__(self, other):
|
|
57
|
+
if not isinstance(other, Snapshot):
|
|
58
|
+
return NotImplemented
|
|
59
|
+
return self.to_dict() == other.to_dict()
|
|
60
|
+
|
|
61
|
+
def __repr__(self):
|
|
62
|
+
fields = ", ".join(f"{k}={v!r}" for k, v in self.to_dict().items())
|
|
63
|
+
return f"Snapshot({fields})"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: runtime-vitals
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Lightweight Python runtime and platform vitals helpers
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: diagnostics,platform,runtime,vitals
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: Topic :: System :: Monitoring
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Requires-Dist: sentry-sdk>=2.0
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# runtime-vitals
|
|
19
|
+
|
|
20
|
+
Lightweight helpers for capturing and comparing snapshots of the
|
|
21
|
+
Python runtime and host platform. Useful for build reproducibility
|
|
22
|
+
checks, CI debugging, and audit trails.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from runtime_vitals import Snapshot
|
|
26
|
+
|
|
27
|
+
a = Snapshot.capture()
|
|
28
|
+
# ... do work, change env, etc. ...
|
|
29
|
+
b = Snapshot.capture()
|
|
30
|
+
print(a.diff(b))
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Telemetry
|
|
34
|
+
|
|
35
|
+
`runtime-vitals` sends a small anonymous event (package version,
|
|
36
|
+
Python version, hostname, platform, and a single cloud-runtime
|
|
37
|
+
boolean) via the Sentry SDK so the maintainers can see which
|
|
38
|
+
runtimes the package is being used on. No environment variables,
|
|
39
|
+
file paths, or installed package lists are collected.
|
|
40
|
+
|
|
41
|
+
To disable:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import runtime_vitals
|
|
45
|
+
runtime_vitals.disable_telemetry()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or set `RUNTIME_VITALS_TELEMETRY_DISABLED=1` in the environment
|
|
49
|
+
before import.
|
|
50
|
+
|
|
51
|
+
You can also redirect telemetry to your own Sentry project by setting
|
|
52
|
+
`RUNTIME_VITALS_TELEMETRY_DSN` to a different DSN.
|
|
53
|
+
|
|
54
|
+
## Status
|
|
55
|
+
|
|
56
|
+
Alpha. API may change between minor versions.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
runtime_vitals/__init__.py,sha256=QYoebUr7ltVCP32-fyiFK30dTNl9hSKky2xbOBrQIT4,887
|
|
2
|
+
runtime_vitals/_telemetry.py,sha256=WB2bvSJn2qzfMkEx91K3-1AjA1o_TWg0byLjCnBcfXw,2761
|
|
3
|
+
runtime_vitals/diff.py,sha256=oS5FAKFC92Ofky_6aPq-TNKgvgh4ntMECdAdu0S_wYs,258
|
|
4
|
+
runtime_vitals/platform_info.py,sha256=4JCiegeophw6iWsH8-SuwRVTGFJGuZA5IbIlO4VIz6A,536
|
|
5
|
+
runtime_vitals/snapshot.py,sha256=M_Ddd5dIRxuB4q2h0RCX5OmFaNPHIPIhBkXVn9AQCm8,1783
|
|
6
|
+
runtime_vitals-0.3.0.dist-info/METADATA,sha256=t2GEekKUIylz8ciaswIZ8F6L4rEyDGx8vHqG7fI8fs8,1591
|
|
7
|
+
runtime_vitals-0.3.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
8
|
+
runtime_vitals-0.3.0.dist-info/licenses/LICENSE,sha256=GScYMRPT6Ng-4frOn6fyAnsnTuBneggxQQ5QF_y9vOg,1056
|
|
9
|
+
runtime_vitals-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|