Context-managed metrics tracking and output, including but not limited to process/subprocess latencies.
Project description
The goblinfish.metrics.trackers Package
Provides context-manager classes to name, track and report elapsed-time and other metrics for top-level process entry-points (like AWS Lambda Function handlers) and sub-processes within them.
Quick Start
Install in your project:
# Install with pip
pip install goblinfish-metrics-trackers
# Install with pipenv
pipenv install goblinfish-metrics-trackers
Import in your code:
from goblinfish.metrics.trackers import ProcessTracker
Create the timing-tracker instance:
tracker = ProcessTracker()
Decorate your top-level/entry-point function:
@tracker.track
def some_function():
...
Add any sub-process timers:
@tracker.track
def some_function():
...
with tracker.timer('some_process_name'):
# Do stuff here
...
When this code is executed, after the context created by the @tracker.track decorator is complete, it will print something that looks like this:
{"some_process_name": 0.0, "some_function": 0.0}
More detailed examples can be found in the examples directory in the repository.
Behavior in an asyncio context
This version will work with processes running under asyncio, for example:
with tracker.timer('some_async_process'):
async.run(some_function())
…but it may only capture the time needed for the async tasks/coroutines to be created rather than how long it takes for any of them to execute, depending on the implementation pattern used.
A more useful approach, shown in the li-article-async-example.py module in the examples directory is to encapsulate the async processes in an async function, then wrap all of that function's processes that need to be timed in the context manager. For example:
async def get_person_data():
sleep_for = random.randrange(2_000, 3_000) / 1000
print(
f'get_person_data sleeping for {sleep_for} seconds'
)
with tracker.timer('get_person_data'):
await asyncio.sleep(sleep_for)
return {'person_data': ('Professor Plum', dict())}
…which will contribute to the logged/printed output in a more meaningful fashion:
// get_person_data sleeping for 2.054
{
"get_person_data": 2.0551600456237793,
"main": 2.8084700107574463
}
Contribution guidelines
At this point, contributions are not accepted — I need to finish configuring the repository, deciding on whether I want to set up automated builds for pull-requests, and probably several other items.
Who do I talk to?
The current maintainer(s) will always be listed in the [maintainers] section of the pyproject.toml file in the repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file goblinfish_metrics_trackers-0.0.4.tar.gz.
File metadata
- Download URL: goblinfish_metrics_trackers-0.0.4.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfd68fd0e224a0431ab5614a39034d2e2b452ae96cc0e2faf8464715a4afdb72
|
|
| MD5 |
e05246f9023e4ebd65e6b2d2237b046c
|
|
| BLAKE2b-256 |
96997c1d0b877711dee2b77e6c609c0e1ac95b58f7d9c6c72415d31bbf3816cc
|
File details
Details for the file goblinfish_metrics_trackers-0.0.4-py3-none-any.whl.
File metadata
- Download URL: goblinfish_metrics_trackers-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64ce74cccd10b53013e9db187c6f6ab6d38c36a463537f530a21a922b96e0aca
|
|
| MD5 |
6daa0d9cca29f9d8ab40dc754341af4e
|
|
| BLAKE2b-256 |
f3ed63d47bd5fb65f62d3e60d23b28adffe09bed57bdc3ca9a3a2e4868d3e56a
|