Skip to main content

alarmer

image image pypi ci

Alarmer is a tool focus on error reporting for your application, like sentry but lightweight.

Installation

pip install alarmer

Usage

It's simple to integrate alarmer in your application, just call Alarmer.init on startup of your application.

import os

from alarmer import Alarmer
from alarmer.provider.feishu import FeiShuProvider


def main():
    Alarmer.init(providers=[FeiShuProvider(webhook_url=os.getenv("FEI_SHU_WEBHOOK_URL"))])
    raise Exception("test")


if __name__ == "__main__":
    main()

Intercept Error Logging

If you want to intercept the logging, you can use LoggingHandler.

import logging
import os

from alarmer import Alarmer
from alarmer.log import LoggingHandler
from alarmer.provider.feishu import FeiShuProvider


def main():
    Alarmer.init(providers=[FeiShuProvider(webhook_url=os.getenv("FEI_SHU_WEBHOOK_URL"))])
    logging.basicConfig(
        level=logging.INFO,
    )
    logger = logging.getLogger()
    logger.addHandler(LoggingHandler(level=logging.ERROR))  # only error and above should be send
    logging.error("test logging")


if __name__ == "__main__":
    main()

Now when you run the script, you will receive the errors in your provider.

Provider

You can set number of providers for error reporting. All kinds of providers can be found in providers.

Thanks to Apprise, you can use lots of providers out of box.

Custom Provider

You can write your own custom provider by inheriting the Provider class.

from typing import Optional
from alarmer.provider import Provider


class CustomProvider(Provider):

    def send(self, message: str, exc: Optional[BaseException] = None, context: Optional[dict] = None):
        # Send to your custom provider here
        pass

In addition to this, you can just write a callable function which takes message and exc arguments.

from typing import Optional


def custom_provider(message: str, exc: Optional[BaseException] = None, context: Optional[dict] = None):
    # Send to your custom provider here
    pass

Then add it to Alarmer.init.

from alarmer import Alarmer

Alarmer.init(providers=[CustomProvider(), custom_provider])

Throttling

Throttling is used to throttling error messages if there are too many errors.

from alarmer import Alarmer
from alarmer.throttling import Throttling

Alarmer.init(global_throttling=Throttling(), providers=[...])

Custom Throttling

You can write your own throttling by inheriting the Throttling class.

import typing

from alarmer.throttling import Throttling

if typing.TYPE_CHECKING:
    from alarmer.provider import Provider


class MyThrottling(Throttling):
    def __call__(self, provider: "typing.Union[Provider,typing.Callable]", message: str,
                 exc: typing.Optional[BaseException] = None, context: typing.Optional[dict] = None) -> bool:
        # check whether the error message should be send
        return True

Manual Send

If you want to manually send messages to the providers, just call Alarmer.send.

from alarmer import Alarmer

Alarmer.send("message")

License

This project is licensed under the Apache-2.0 License.

Metadata

Release files for alarmer 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alarmer 0.1.4
File Size Uploaded
alarmer-0.1.4.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alarmer 0.1.4
File Interpreter ABI Platform
alarmer-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / alarmer-0.1.4.tar.gz

Download URL alarmer-0.1.4.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7d6fc1ff7d750c79da4d05d28e08f89df110e9491305ddd85df9ab3e02fac5c0
BLAKE2b-256 checksum
How to use checksums
db2f030ae7f5d28f6911ae780fa2ee3bd7c9db2b81f798d2b393e75c7df0b9a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / alarmer-0.1.4-py3-none-any.whl

Download URL alarmer-0.1.4-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0189b173c676418cf10ba9a32550aae9dd195ac6106adc513b4d26cddfec374b
BLAKE2b-256 checksum
How to use checksums
1453135218bacd838e3a4814be94f6f285705b1ada7792a11481528d112b1315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page