Skip to main content

craftainer-observability

Observability building blocks for FastAPI services: a health check framework with /live and /ready routes and generic dependency checks, structured JSON logging, OpenTelemetry traces and metrics, a request-ID middleware and opt-in request profiling. It is extracted from template-fastapi and is an instance of template-python-package (see docs/TEMPLATE.md for the conventions shared with every instance). It never imports an application package or craftainer_crud; an import-linter contract enforces that.

Install

The distribution is craftainer-observability, the import package craftainer_observability. The core needs FastAPI only; everything else is an extra, so install what you use:

pip install craftainer-observability                    # health framework, request IDs
pip install "craftainer-observability[otel,redis]"      # plus tracing/metrics/logs, Redis check
Extra Brings Used by
otel OpenTelemetry SDK, OTLP/HTTP exporters, logging, FastAPI and SQLAlchemy instrumentations (and SQLAlchemy, which otel.py imports for typing) logs.py, otel.py
sqlalchemy SQLAlchemy (asyncio) health.checks.postgres.PostgresCheck
redis redis-py health.checks.redis.RedisCheck
s3 boto3 health.checks.s3.S3Check
http httpx health.checks.http.HTTPCheck
profiling pyinstrument profiling.install_profiling

logs.py and otel.py import OpenTelemetry at module level, so import them only when [otel] is installed. The package root, health and middleware import with no extra installed (a unit test proves it). Note that opentelemetry-sqlalchemy instrumentation supports SQLAlchemy below 2.1 only, hence the <2.1 bound.

Public API

Module Provides
health HealthCheck, HealthCheckResult, HealthRegistry, build_health_router(get_registry, include_info=False, info_package=None)
health.checks PostgresCheck, RedisCheck, S3Check, HTTPCheck (one module each)
logs configure_logging(), shared_resource()
otel configure_telemetry(), instrument_app(app), instrument_engine(engine)
middleware RequestIDMiddleware, get_request_id()
profiling install_profiling(app, *, enabled, production, query_param="profile")

The details, environment variables and conventions are in src/craftainer_observability/README.md.

Versioning

SemVer, starting at 0.1.0. While the major version is 0, a minor release may change the public API; pin craftainer-observability>=0.x,<0.(x+1) until 1.0. Real-service integration tests for the dependency checks stay in template-fastapi; the unit tests here use fakes and need no backing service.

Development

uv sync
prek run --all-files --hook-stage manual   # lint, types, import contracts, unit tests (100% coverage)
uv run pytest tests/bench --no-cov         # benchmarks (CodSpeed in CI)

Publishing to PyPI

Releases use PyPI trusted publishing (GitHub OIDC): no API token is stored anywhere. make publish is a no-op until you opt in, per repository:

  1. Register a "pending publisher" on the index before the first release (PyPI: Your account, Publishing, "Add a new pending publisher"; TestPyPI has its own, separate form on test.pypi.org). Enter the project name from pyproject.toml, the GitHub owner and repository, the workflow name release.yml, and leave the environment empty (or use the one release.yml runs under, if you add one).
  2. Set the repository variable PYPI_PUBLISH (Settings, Secrets and variables, Actions, Variables):
    • unset: make publish prints a skip message and the release only attaches the sdist, wheel and SBOM to the GitHub release;
    • testpypi: publish to TestPyPI;
    • pypi: publish to PyPI.
  3. Do the first release with testpypi as a dry run (a pre-release channel is enough), confirm that make release-check installs the published version back from TestPyPI, then register the PyPI pending publisher and switch the variable to pypi.

The version lives only in the git tag release.yml computes; pyproject.toml stays at 0.0.0 and make build stamps RELEASE_VERSION into the build without committing it.

License

Licensed under the GNU General Public License v3.0.

Metadata

Release files for craftainer-observability 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for craftainer-observability 0.2.0
File Size Uploaded Provenance
craftainer_observability-0.2.0.tar.gz 193.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for craftainer-observability 0.2.0
File Interpreter ABI Platform
craftainer_observability-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 228.2 kB

Release files / craftainer_observability-0.2.0.tar.gz

Download URL craftainer_observability-0.2.0.tar.gz
Size 193.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cc91025c4f4a32a71ce4a3925776e167364f07db3783da856fd6ffed6715070f
BLAKE2b-256 checksum
How to use checksums
ce4decaf23d4989e11e0bfc82fd25dab03882e53bb93ce8c2cea05d1fe284240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / craftainer_observability-0.2.0-py3-none-any.whl

Download URL craftainer_observability-0.2.0-py3-none-any.whl
Size 35.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebebdd498c1e0c1b0d09d420e319a4a5b285dd6a4de9f7468c057b8d3be901d5
BLAKE2b-256 checksum
How to use checksums
6df7a4766621393926d9f7cbbeba81eedb61a9db63a9a54d0acbc96bb96dff83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for craftainer-observability 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page