This package provides a decorator to wrap around a function so that a report is sent to external server every time function runs.
Project description
function-ext-monitor
This package provides a decorator to wrap around a function so that a report is sent to external server every time function runs.
Dependencies
How to install
-
Run the command below in your terminal
pip install function-ext-monitor
How to use
-
Given that the function you wish to monitor is the
simple_addition
function in the code below,here is how you would go about it.import datetime from function_ext_monitor import external_function_monitor EXTRA_DATA_TO_SEND = { # maybe how often do you expect this function to be called 'interval_in_seconds': 7, # maybe who wrote it 'author': 'John Doe', # even functions without arguments can be added to dynamically # generate values when the function is called # They should return something JSON serializable 'timestamp': lambda: str(datetime.datetime.now()), 'headers': { # Any custom headers. Again, feel free to pass in a function # to generate headers on the fly, 'Authorization': 'Bearer your-auth-token', } .... } @external_function_monitor('http://endpoint-to-send-data-to', **EXTRA_DATA_TO_SEND) def simple_addition(first_number, second_number): """ This function adds the first_number to the second_number and returns the sum """ return first_number + second_number
Note
- By default, the decorator includes the name of the computer and the name of the function in the data sent to the remote endpoint.
- If the decorator is around a method of a class, the full name in the format
Class_name.method_name
is sent to the remote endpoint. - It also adds
'Content-Type': 'application/json'
to the headers - It sends the data by spinning up a separate process so that interference with the running program is minimal
- Every time the function it decorates (in the above example
simple_addition
) runs, a POST request is sent the remote server specified in the first argument. It is upto the developer to decide whether they will overwrite the existing record for that function or to keep a continuously growing log of records on that function.
Acknowledgment
The RealPython post on python packaging was very helpful when I was publishing this package.
License
Copyright (c) 2020 Martin Ahindura Licensed under the MIT License
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
File details
Details for the file function-ext-monitor-0.0.6.tar.gz
.
File metadata
- Download URL: function-ext-monitor-0.0.6.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f36d51e38a9d2a95b8c7efb3eccf5e4168babeb3fb1de6e665f2ad506054e0b4 |
|
MD5 | afb63bd384b7abb0399bd74ff4ca1a43 |
|
BLAKE2b-256 | 8939cfd44972511e1ff85e2683ce7c44e27fefdf4f8f7dc7a1c142286ca21b3b |
File details
Details for the file function_ext_monitor-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: function_ext_monitor-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a4792315b9067e66fa994392b205e00cd4e1dda642d53e81497340de10b3c30 |
|
MD5 | 51d572bf6e75e39ecd8c4f167dff7640 |
|
BLAKE2b-256 | d7fc65a9fcd87af2ae137120691ba54bc1dc8f3b2bce2072eff8cf2d7b381bb9 |