Skip to main content

Framework-agnostic metrics and structured log collection with hexagonal architecture

Project description

observabilipy

Framework-agnostic metrics and structured log collection with hexagonal architecture.

Develop observability features decoupled from your infrastructure. Use embedded storage (SQLite, in-memory) during development, then optionally expose endpoints for scraping by Prometheus, Grafana Alloy, or other observability platforms when you're ready.

Features

  • Prometheus-style metrics - /metrics endpoint in text format
  • Structured logs - /logs endpoint in NDJSON (Grafana Alloy compatible)
  • Framework adapters - FastAPI, Django, generic ASGI
  • Storage backends - In-memory, SQLite (with WAL), Ring buffer
  • Retention policies - Automatic cleanup with EmbeddedRuntime

Installation

git clone https://github.com/PhilHem/observabilipy.git
cd observabilipy
uv sync

For framework support:

uv sync --extra fastapi
uv sync --extra django

Quick Start

from fastapi import FastAPI
from observability.adapters.frameworks.fastapi import create_observability_router
from observability.adapters.storage.in_memory import (
    InMemoryLogStorage,
    InMemoryMetricsStorage,
)

app = FastAPI()
log_storage = InMemoryLogStorage()
metrics_storage = InMemoryMetricsStorage()

app.include_router(create_observability_router(log_storage, metrics_storage))

Run with uvicorn and visit /metrics and /logs.

Recording Metrics and Logs

import time
from observability.core.models import LogEntry, MetricSample

# Record a log entry
await log_storage.write(
    LogEntry(
        timestamp=time.time(),
        level="INFO",
        message="User logged in",
        attributes={"user_id": 123, "ip": "192.168.1.1"},
    )
)

# Record a metric sample
await metrics_storage.write(
    MetricSample(
        name="http_requests_total",
        timestamp=time.time(),
        value=1.0,
        labels={"method": "GET", "path": "/api/users"},
    )
)

Storage Backends

Backend Use Case
InMemoryLogStorage / InMemoryMetricsStorage Development and testing
SQLiteLogStorage / SQLiteMetricsStorage Persistent storage with WAL mode for concurrent access
RingBufferLogStorage / RingBufferMetricsStorage Fixed-size buffer for memory-constrained environments

All backends implement the same port interfaces and are interchangeable.

Examples

See the examples/ directory:

Example Description
minimal_example.py Dummy metrics and logs generator for testing
cgroups_example.py Container CPU and memory metrics from cgroups v2
fastapi_example.py Basic FastAPI setup with in-memory storage
django_example.py Django integration
asgi_example.py Generic ASGI middleware
sqlite_example.py Persistent storage with SQLite
ring_buffer_example.py Fixed-size storage for constrained environments
embedded_runtime_example.py Background retention cleanup

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

observabilipy-0.10.2.tar.gz (75.7 kB view details)

Uploaded Source

Built Distribution

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

observabilipy-0.10.2-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file observabilipy-0.10.2.tar.gz.

File metadata

  • Download URL: observabilipy-0.10.2.tar.gz
  • Upload date:
  • Size: 75.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for observabilipy-0.10.2.tar.gz
Algorithm Hash digest
SHA256 c2cd274f4e7e9b0bb1359fbfb955ec11f7a8ecc5c95739476d1ba3b7054784e2
MD5 5a1c0dab01ddf41ff171dc4b572063e3
BLAKE2b-256 23891de14e273b599793091a86a620a8073c4ac6c1183fe1322f0a053f16c8ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for observabilipy-0.10.2.tar.gz:

Publisher: release.yml on PhilHem/observabilipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file observabilipy-0.10.2-py3-none-any.whl.

File metadata

  • Download URL: observabilipy-0.10.2-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for observabilipy-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ca5415772b1845f84c25c72bc545c7ce854f3fe97bbfeaf8e601c10b3763cf
MD5 c17462c9a295fdbbd1027676afa27ac4
BLAKE2b-256 a7a84a013fb4ec5bf7a4627ec510bc990e556f528b586aff77c2aeb9c3db4da5

See more details on using hashes here.

Provenance

The following attestation bundles were made for observabilipy-0.10.2-py3-none-any.whl:

Publisher: release.yml on PhilHem/observabilipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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