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 (21 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.0b2.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.0b2-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: domprob-0.1.0b2.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.0b2.tar.gz
Algorithm Hash digest
SHA256 a7387838295b64f958213450141633cbef467775b3a5d40dc3e580b47160c41d
MD5 df0eacea7397920a8f0a7ebdff42cc5e
BLAKE2b-256 6beb028dc0f1bb8e838740b8b4ac2b18a4485f58154b0905f0f9c362bc8cd88e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: domprob-0.1.0b2-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.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd76d94a1ac0c298dbcf398585e963fb22a20596001c59f0daacfa4079adbc40
MD5 05301d128c1fef832e2eee1b1a0a4af0
BLAKE2b-256 f966609c80215593f5f3de9501899e6ed628d7b6b3b84bf8b34b8e10bfc8a062

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