Skip to main content

Periskop Python client

Project description

periskop-python

Build Status

Periskop requires collecting and aggregating exceptions on the client side, as well as exposing them via an HTTP endpoint using a well defined format.

This library provides low level collection and rendering capabilities

Install

pip install periskop-client

Usage example

import json
from http.server import HTTPServer

from periskop_client.collector import ExceptionCollector
from periskop_client.exporter import ExceptionExporter
from periskop_client.handler import exception_http_handler
from periskop_client.models import HTTPContext


def faulty_json():
    return json.loads('{"id":')


if __name__ == "__main__":
    collector = ExceptionCollector()
    try:
        faulty_json()
    except Exception as exception:
        # Report without context
        collector.report(exception)
        # Report with HTTP context
        collector.report_with_context(
            exception,
            HTTPContext("GET", "http://example.com", {"Cache-Control": "no-cache"}),
        )

    # Expose collected exceptions in localhost:8081/-/exceptions
    server_address = ("", 8081)
    handler = exception_http_handler(
        path="/-/exceptions", exporter=ExceptionExporter(collector)
    )
    http_server = HTTPServer(server_address, handler)
    http_server.serve_forever()

Run tests

For running tests pytest is needed. A recommended way to run all check is installing tox and then just type tox. This will run pytest tests, black formatter and flake8 and mypy static code analyzers.

Alternatively you can run pip install -r requirements-tests.txt and then run pytest.

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

periskop-client-0.1.0.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

periskop_client-0.1.0-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page