Repository navigation
feat(observability): make the concrete sinks importable from servicewright.adapters.observability - #17
Merged
Conversation
…right.adapters.observability Instance injection is the documented way to configure a backend (PrometheusMetricsSink(registry=...), SentryErrorTrackingSink(ignore_errors=[...])), but the five concrete classes only existed under the private _metrics / _tracing / _errors / _logging packages, so the only working import reached through two underscore-prefixed modules and the docstrings that show the pattern gave no import line. The backends are now attributes of servicewright.adapters.observability, resolved lazily through a module-level __getattr__ (PEP 562): the package stays importable with no extra installed, and asking for a backend whose extra is missing raises the same ImportError that names the extra, only for that backend. __dir__ lists them; under TYPE_CHECKING they are static explicit re-exports, so type checkers and IDEs see the real classes. Closes #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #16 — the concrete sinks are importable from a public path.
Problem. Instance injection is the documented way to configure a backend, but
PrometheusMetricsSink,OtelTracingSink,SentryErrorTrackingSink,StructlogLoggingSinkandStdlibLoggingSinkonly existed under the private_metrics/_tracing/_errors/_loggingpackages, and the docstrings that show the pattern gave no import line.Design.
servicewright.adapters.observability, resolved lazily through a module-level__getattr__(PEP 562). The package stays importable with no extra installed — pinned by a subprocess test that imports it and asserts no SDK module was loaded — and asking for a backend whose extra is missing raises that backend's ownImportErrornaming the extra, only for that backend.__dir__lists them; they are in__all__; underTYPE_CHECKINGthey are static explicit re-exports, so mypy resolvesfrom servicewright.adapters.observability import SentryErrorTrackingSinkto the real class (reveal_typeconfirms), notAny.SentryErrorTrackingSinkdocstring, the observability concept page (instance injection) and the Sentry backend page now carry the import line; the API reference lists the backends.Rejected (details in the plan comment on #16): exporting from the package root (the root is the kernel's vocabulary and stays extra-free); factories with private classes (the classes already are the documented configuration surface); eager re-exports (unimportable unless every extra is installed).
Type of change
Checklist
dir(), unknown name →AttributeError, missing extra → install hint for that backend only, package import pulls in no SDK; the 7 that pin the new behaviour fail againstmaster's__init__.py(AttributeError)make checkpasses locally (ruff+mypy+lint-imports)CHANGELOG.md— generated by release-please from thefeat:commitVerification
make check: clean (ruff, ruff format, mypy over 110 files, import-linter — 3 contracts kept)pytest -m unit --cov-fail-under=90: 636 passed, 10 skipped, coverage 93.12%zensical build --clean: no issuesmypyon a consumer snippet:reveal_type(SentryErrorTrackingSink)is the concrete classRelated issues
Closes #16