Observe
@observe is a decorator for Python methods, which allows Python developers to collect all basic metrics about the decorated method, generate unified logs and notifications on failure which are easy to trace.
Installation
pip install atl-observe
Usage
Decorating the process method and assigning a metic name and static_tags, all tags are added to all metrics generated, used to filter on your dashboards.
from atl_observe import observe
class Engine:
@observe(metric="process",
static_tags=["layer:process"])
def process(self, message: dict):
pass
Decorating the process method and assigning a metric and trace_id_from, the trace_id will now appear in all logs and notifications, used to search your logs.
from atl_observe import observe
class Engine:
@observe(metric="process",
trace_id_from={"message": "eventId"})
def process(self, message: dict):
pass
Logs, Metrics and Notifications
All logs, metrics and notifications are divided into three categories:
- Default: no exceptions were raised.
- Expected: an expected Exception was raised.
- Unexpected Exceptions: an unexpected / unhandled Exception was raised
Default
# optional: debug logs
logger.debug("... start.")
logger.debug("... finished.")
# increments
statsd.increment("%s.start" % metric, 1, tags=all_tags)
statsd.increment("%s.finished" % metric, 1, tags=all_tags)
# timing
statsd.timing("%s.time.finished" % metric, dt, tags=all_tags)
Expected
Expected exceptions are managed via accept_on and decline_on lists. If the raised exception is part of accept_on, the decorator will return a Truthy value, if the exception is part of decline_on a Falsy value is returned.
# warning logs
logger.warning("... accepted.")
logger.warning("... declined.")
# increments
statsd.increment('%s.exception.accepted' % metric, tags=all_tags)
statsd.increment('%s.exception.declined' % metric, tags=all_tags)
# timing
statsd.timing("%s.time.accepted" % metric, dt, tags=all_tags)
statsd.timing("%s.time.declined" % metric, dt, tags=all_tags)
Unexpected
# error logs
logger.error("... raised.")
# slack
slack.error("... raised.")
# increments
statsd.increment('%s.exception.raised' % metric, tags=all_tags)
# timing
statsd.timing("%s.time.raised" % metric, dt, tags=all_tags)
Documentation
make installwill install all required packagesmake formatwill auto format the projectmake lintwill run the lintermake testswill run all unit tests
Contributions
Contributions to @observe are welcome! Please see CONTRIBUTING.md for details.
License
Copyright (c) [2020] Atlassian and others. Apache 2.0 licensed, see LICENSE file.
Metadata
Release files for atl-observe 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| atl-observe-1.1.0.tar.gz | 9.1 kB | Without provenance | Details for atl-observe-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| atl_observe-1.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for atl_observe-1.1.0-py2.py3-none-any.whl |
Total release size: 22.6 kB
Release files / atl-observe-1.1.0.tar.gz
| Download URL | atl-observe-1.1.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59a71c1bb8a1137a179a883afb3dff4d6721b4957883948acb47044df69b4103
|
|
BLAKE2b-256 checksum How to use checksums |
ad13fd1424a5405f3b66040ac3cb0e174d9bf5d21854db9cb47fcbb02dabb763
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
|
Release files / atl_observe-1.1.0-py2.py3-none-any.whl
| Download URL | atl_observe-1.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
75b738df0f945df1208c67b839ce104863a9d992005b4e27813270e1c0b3e188
|
|
BLAKE2b-256 checksum How to use checksums |
afff313798d4ec81a9f44298198c0d9418db42764bfea5e2703c79665fd60db9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
|
Security for atl-observe 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.