Skip to main content

Python package to implement observability domain probes

Project description

domprob 🛰️

Inspired by this blog post, domprob is a Python package to implement observability domain probes in your projects.

PyPI - Package Version PyPI - Python Version codecov pre-commit Checked with mypy Code style: black

📄 Documentation | 🐍 PyPI

Overview

Keep your business logic comprehensible by abstracting the observability code away.

Turn this (20 lines):

class OrderService:
    def checkout(self):
        self.logger.log(f"Attempting to checkout order {self.order}")
        try:
            self.checkout_service.checkout_order(self.order)
        except CheckoutError as e:
            self.logger.error(f"Checkout for order {self.order} failed: {e}")
            self.metrics.increment("checkout-failed", {
                "failed_orders": 1, "customer": 6234654
            })
            return
        self.metrics.increment("checkout-successful", {
            "successful_orders": 1, 
         })
        self.logger.log(f"Order checkout completed successfully", {
            "successful_orders": 1, 
            "customer": 6234654, 
            "order_number": 2374, 
            "sku": "JH-374-VJHV"
        })

→ Into ✨this✨ (9 lines):

class Order:
    def checkout(self):
        probe.observe(AttemptingCheckoutObservation())
        try:
            self.checkout_service.checkout_order(self.order)
        except CheckoutError as e:
            probe.observe(CheckoutFailedObservation())
            return
        probe.observe(CheckoutSuccessfulObservation())

Installation

Install using uv:

uv add domprob

Using pip:

pip install domprob

Using poetry:

poetry add domprob

Usage

Define an observation

import logging
from typing import Any

from domprob import announcement, BaseObservation


class CheckoutSuccessful(BaseObservation):
    
        def __init__(self, **order_details: Any) -> None:
            self.order_details = order_details

        @announcement(logging.Logger)
        def log_observation(self, log: logging.Logger) -> None:
           log.info("Checkout successful!", **self.order_details)

Calling the observation

   from domprob import probe

   class OrderService:
       
       def checkout(self):
           try:
               self.checkout_service.checkout_order(self.order)
           except CheckoutError as e:
               raise
           probe.observe(CheckoutSuccessful(**self.order_entity))

Check out the docs for more detail!

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

domprob-0.1.0rc0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

domprob-0.1.0rc0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file domprob-0.1.0rc0.tar.gz.

File metadata

  • Download URL: domprob-0.1.0rc0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for domprob-0.1.0rc0.tar.gz
Algorithm Hash digest
SHA256 66f8a4b63db099ba40e890c3d382e1090a3a01dd425fc7b5e8eea0ca2ed3fee1
MD5 3cf9b9094c95c81c66cd41c0b9a81532
BLAKE2b-256 f23f7cb9f61afa00e4d8d740e86f7d1035799bbcef76dfec8a3dfc6cdf6fde15

See more details on using hashes here.

File details

Details for the file domprob-0.1.0rc0-py3-none-any.whl.

File metadata

  • Download URL: domprob-0.1.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for domprob-0.1.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 f615a57ea774614ae52d93ef0da17837c022b1d17d2fc6ce335c6e7b01483566
MD5 a00beaa8992ec24c22a79de8be74722a
BLAKE2b-256 78fd65f19bf821822a03092f9f81d9455057a3b4218a5f32d5a32c54ea667c8c

See more details on using hashes here.

Supported by

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