Skip to main content

Python package to implement observability domain probes

Project description

domprob 🛰️

Observability Domain Probes Python Package

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

📄 Documentation | 🐍 PyPI

 

domprob 🛰️

Implement the domain probe pattern with observability events easily with domprob.

Motivation

Observability often focuses on low-level signals, missing domain-specific insights that explain why a system behaves a certain way. Inspired by this blog post titled "Domain-Oriented Observability", domprob helps expose meaningful domain events and causal relationships, enabling teams to reason about their system in business terms.

Key Features

Tidy Domain Logic: Keeps domain logic clean by separating observability concerns, ensuring insights don’t clutter core business code.

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

uv

uv add domprob

poetry

poetry add domprob

pip

pip install domprob

Usage

Define an observation:

import logging
from typing import Any

from domprob import sensor, BaseObservation


class CheckoutSuccessful(BaseObservation):

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

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

Calling the observation:

import logging
from domprob import get_probe

probe = get_probe(logging.getLogger(__name__))


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 detailed examples!

Contributing

  • Our code of conduct is here.
  • Check out all our issues here. We've compiled a least of good first issues here.

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-1.0.0a0.tar.gz (45.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-1.0.0a0-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

Details for the file domprob-1.0.0a0.tar.gz.

File metadata

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

File hashes

Hashes for domprob-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 dc9b6d29e852480c6158746f82df0ad5a3457bd03d800df9195ad157270ffa2a
MD5 44693b4035e9ef73bce2b676b5ff1def
BLAKE2b-256 94f4d0193b529078d18603a8c8f3de80560e2e8ad79708e2395bbf44ff66f89e

See more details on using hashes here.

File details

Details for the file domprob-1.0.0a0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for domprob-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 94f236b542e0b614387dabbc032be00bc21763099b253f2b91b59015ea04682e
MD5 5f8abfa6c845c5a49d2fea9e55388b08
BLAKE2b-256 cf54c1959b78133a009e35b66169be3ff9aed0b24310a0b1485323170a97f43c

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