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.announce(AttemptingCheckoutObservation())
        try:
            self.checkout_service.checkout_order(self.order)
        except CheckoutError as e:
            probe.announce(CheckoutFailedObservation())
            return
        probe.announce(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.0b1.tar.gz (31.0 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.0b1-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: domprob-0.1.0b1.tar.gz
  • Upload date:
  • Size: 31.0 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.0b1.tar.gz
Algorithm Hash digest
SHA256 0c3f300e1046b369c7a6c2b85df004d5c2db34d607d35cfeec832a749bae52de
MD5 99000534c02695b70aeca5ae1aa2f189
BLAKE2b-256 b69b36ae5a8780b8bc758dcd235d2363998b20e38bb50403f6d709814b9f1814

See more details on using hashes here.

File details

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

File metadata

  • Download URL: domprob-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 39.0 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.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 e46c1693f5478c7d433a72c9aa6f2ffee84963ae9c9aa29ac490e1b85ff1de2e
MD5 27321151b0daf9149de6afd43ea39671
BLAKE2b-256 74dbeb53065854b93b63f6d6221c1cbf9d03f1f03b8498ca10a7fa313019acda

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