Skip to content

feat(observability): make the concrete sinks importable from servicewright.adapters.observability - #17

Merged
AlexeyShalaev merged 1 commit into
masterfrom
feat/public-sink-imports
Aug 29, 2026
Merged

AlexeyShalaev merged 1 commit into
masterfrom
feat/public-sink-imports

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

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, StructlogLoggingSink and StdlibLoggingSink only existed under the private _metrics / _tracing / _errors / _logging packages, and the docstrings that show the pattern gave no import line.

Design.

  • The five backends are attributes of 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 own ImportError naming the extra, only for that backend. __dir__ lists them; they are in __all__; under TYPE_CHECKING they are static explicit re-exports, so mypy resolves from servicewright.adapters.observability import SentryErrorTrackingSink to the real class (reveal_type confirms), not Any.
  • Docs: the SentryErrorTrackingSink docstring, 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring / internal

Checklist

  • Tests added or updated — public path resolves to the private class (×5), 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 against master's __init__.py (AttributeError)
  • make check passes locally (ruff + mypy + lint-imports)
  • CHANGELOG.md — generated by release-please from the feat: commit
  • Documentation updated (if the public API changed)

Verification

  • 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 issues
  • mypy on a consumer snippet: reveal_type(SentryErrorTrackingSink) is the concrete class

Related issues

Closes #16

…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
@AlexeyShalaev
AlexeyShalaev merged commit 0a04252 into master Aug 29, 2026
6 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the feat/public-sink-imports branch September 6, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: the concrete sinks its own docs tell you to construct are only importable from a private path

1 participant