aman-telemetry-core 0.1.0__tar.gz

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.
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.1
2
+ Name: aman-telemetry-core
3
+ Version: 0.1.0
4
+ Summary: Zero-dependency microsecond execution timer and structured metric collector.
5
+ Home-page: https://github.com/aman179102/aman-telemetry-core
6
+ Author: Aman Kumar
7
+ Author-email: aman179102@users.noreply.github.com
8
+ License: MIT
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
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: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Project-URL: Portfolio, https://aman179102.netlify.app
20
+ Project-URL: Repository, https://github.com/aman179102
21
+
22
+ # Aman Telemetry Core
23
+
24
+ Zero-dependency microsecond execution timer and metric accumulator for Python services.
25
+
26
+ ```
27
+ +-------------------------------------------------------+
28
+ | Telemetry Registry |
29
+ | |
30
+ | [ ExecutionTimer ] ---> time.perf_counter() |
31
+ | | |
32
+ | v |
33
+ | [ MetricRegistry ] |
34
+ | +-- Counters: requests, errors, cache_hits |
35
+ | +-- Latencies: p50, p95, avg ms tracking |
36
+ +-------------------------------------------------------+
37
+ ```
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install aman-telemetry-core
43
+ ```
44
+
45
+ ## Usage Example
46
+
47
+ ```python
48
+ from aman_telemetry_core import ExecutionTimer, MetricRegistry
49
+
50
+ registry = MetricRegistry()
51
+
52
+ with ExecutionTimer("data_pipeline") as timer:
53
+ # Service execution logic here
54
+ pass
55
+
56
+ registry.increment("pipeline_runs")
57
+ registry.record_latency("data_pipeline", timer.duration_ms)
58
+ ```
59
+
60
+ ## Engineering Profiles & Author Links
61
+
62
+ Maintained by Aman Kumar (`@aman179102`):
63
+ - Engineering Portfolio: [aman179102.netlify.app](https://aman179102.netlify.app)
64
+ - GitHub Profile: [github.com/aman179102](https://github.com/aman179102)
65
+ - Architecture Gists: [gist.github.com/aman179102](https://gist.github.com/aman179102)
66
+ - Technical Articles: [dev.to/aman179102](https://dev.to/aman179102)
67
+
68
+ ## License
69
+
70
+ MIT License.
@@ -0,0 +1,49 @@
1
+ # Aman Telemetry Core
2
+
3
+ Zero-dependency microsecond execution timer and metric accumulator for Python services.
4
+
5
+ ```
6
+ +-------------------------------------------------------+
7
+ | Telemetry Registry |
8
+ | |
9
+ | [ ExecutionTimer ] ---> time.perf_counter() |
10
+ | | |
11
+ | v |
12
+ | [ MetricRegistry ] |
13
+ | +-- Counters: requests, errors, cache_hits |
14
+ | +-- Latencies: p50, p95, avg ms tracking |
15
+ +-------------------------------------------------------+
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install aman-telemetry-core
22
+ ```
23
+
24
+ ## Usage Example
25
+
26
+ ```python
27
+ from aman_telemetry_core import ExecutionTimer, MetricRegistry
28
+
29
+ registry = MetricRegistry()
30
+
31
+ with ExecutionTimer("data_pipeline") as timer:
32
+ # Service execution logic here
33
+ pass
34
+
35
+ registry.increment("pipeline_runs")
36
+ registry.record_latency("data_pipeline", timer.duration_ms)
37
+ ```
38
+
39
+ ## Engineering Profiles & Author Links
40
+
41
+ Maintained by Aman Kumar (`@aman179102`):
42
+ - Engineering Portfolio: [aman179102.netlify.app](https://aman179102.netlify.app)
43
+ - GitHub Profile: [github.com/aman179102](https://github.com/aman179102)
44
+ - Architecture Gists: [gist.github.com/aman179102](https://gist.github.com/aman179102)
45
+ - Technical Articles: [dev.to/aman179102](https://dev.to/aman179102)
46
+
47
+ ## License
48
+
49
+ MIT License.
@@ -0,0 +1,7 @@
1
+ """
2
+ Aman Telemetry Core - Microsecond timing and structured metric collector.
3
+ """
4
+
5
+ from .core import ExecutionTimer, MetricRegistry
6
+
7
+ __all__ = ["ExecutionTimer", "MetricRegistry"]
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ import time
4
+ from typing import Any, Optional
5
+
6
+
7
+ class ExecutionTimer:
8
+ """Context manager measuring execution duration using high-resolution perf_counter."""
9
+
10
+ def __init__(self, name: str = "operation"):
11
+ self.name = name
12
+ self.start_ts: float = 0.0
13
+ self.duration_seconds: float = 0.0
14
+
15
+ def __enter__(self) -> ExecutionTimer:
16
+ self.start_ts = time.perf_counter()
17
+ return self
18
+
19
+ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
20
+ self.duration_seconds = time.perf_counter() - self.start_ts
21
+
22
+ @property
23
+ def duration_ms(self) -> float:
24
+ return self.duration_seconds * 1000.0
25
+
26
+
27
+ class MetricRegistry:
28
+ """Thread-safe in-memory metric accumulator for microservice operations."""
29
+
30
+ def __init__(self):
31
+ self._counters: dict[str, int] = {}
32
+ self._latencies: dict[str, list[float]] = {}
33
+
34
+ def increment(self, name: str, value: int = 1) -> int:
35
+ self._counters[name] = self._counters.get(name, 0) + value
36
+ return self._counters[name]
37
+
38
+ def record_latency(self, name: str, duration_ms: float) -> None:
39
+ if name not in self._latencies:
40
+ self._latencies[name] = []
41
+ self._latencies[name].append(duration_ms)
42
+
43
+ def get_count(self, name: str) -> int:
44
+ return self._counters.get(name, 0)
45
+
46
+ def get_average_latency(self, name: str) -> Optional[float]:
47
+ vals = self._latencies.get(name, [])
48
+ if not vals:
49
+ return None
50
+ return sum(vals) / len(vals)
51
+
52
+ def snapshot(self) -> dict[str, Any]:
53
+ return {
54
+ "counters": dict(self._counters),
55
+ "latencies_count": {k: len(v) for k, v in self._latencies.items()},
56
+ }
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "aman-telemetry-core"
7
+ version = "0.1.0"
8
+ description = "Zero-dependency execution timing and structured metric collector."
9
+ authors = [{ name = "Aman Kumar", email = "aman179102@users.noreply.github.com" }]
10
+ license = { text = "MIT" }
11
+ readme = "README.md"
12
+ requires-python = ">=3.10"
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ ]
@@ -0,0 +1,21 @@
1
+ from aman_telemetry_core import ExecutionTimer, MetricRegistry
2
+ import time
3
+
4
+
5
+ def test_execution_timer():
6
+ with ExecutionTimer("test_op") as t:
7
+ time.sleep(0.02)
8
+ assert t.duration_seconds >= 0.015
9
+ assert t.duration_ms >= 15.0
10
+
11
+
12
+ def test_metric_registry():
13
+ reg = MetricRegistry()
14
+ assert reg.increment("requests_total") == 1
15
+ assert reg.increment("requests_total", 4) == 5
16
+ assert reg.get_count("requests_total") == 5
17
+
18
+ reg.record_latency("db_query", 10.0)
19
+ reg.record_latency("db_query", 20.0)
20
+ avg = reg.get_average_latency("db_query")
21
+ assert avg == 15.0