Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

craftainer-tool-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_tool_crud; an import-linter contract enforces that.

Install

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

pip install craftainer-tool-observability                    # health framework, request IDs
pip install "craftainer-tool-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_tool_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-tool-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-tool-observability 0.1.1

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-tool-observability 0.1.1
File Size Uploaded Provenance
craftainer_tool_observability-0.1.1.tar.gz 192.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 227.5 kB

Release files / craftainer_tool_observability-0.1.1.tar.gz

Download URL craftainer_tool_observability-0.1.1.tar.gz
Size 192.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f27aeb5f1213b8da8f46040a009203d4bc54e2a83275e09ccc05607a00277e15
BLAKE2b-256 checksum
How to use checksums
fede47a8554bafa35d603444a6cd6685ce608e1db085352eb69e9cb4307888a0
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_tool_observability-0.1.1-py3-none-any.whl

Download URL craftainer_tool_observability-0.1.1-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7c142f5aa4b23c6815ae20624217118a8b545db5bc72acabff43eb20b4a8948
BLAKE2b-256 checksum
How to use checksums
84908f2fdeab89bf3ba6095bc302b9d7342f90c5a51906bfaffba487de1e4276
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-tool-observability 0.1.1

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.

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