Background
Raised during review of PR #303 by @leynos.
Domain functions in src/wrap/inline/ and src/wrap/tokenize/ currently import and use the vendor-specific tracing framework directly (#[tracing::instrument], debug!, trace!, tracing::enabled!). This couples infrastructure concerns to domain logic, making the domain harder to test without a tracing subscriber and harder to migrate to a different observability backend in the future.
Required work
- Define domain-level event types — e.g.
enum ClassificationEvent — that capture the observable outcomes of classification and parsing decisions without referencing any external crate.
- Refactor classification functions (
classify_fragment_kind, parse_link_or_image, find_footnote_end, the footnote predicate helpers) to accept an optional observer (e.g. a callback or a trait object implementing an Observer trait) and emit domain events through it, rather than emitting tracing calls inline.
- Implement a
tracing-backed adapter that translates ClassificationEvent values into the appropriate debug!/trace! calls. Wire this adapter at the library boundary so existing instrumented behaviour is preserved.
- Remove direct
tracing imports from all domain modules; retain the dependency only in the adapter layer and in [dev-dependencies] for tests.
Acceptance criteria
- No
use tracing:: import appears inside domain modules (src/wrap/inline/, src/wrap/tokenize/).
- Domain functions can be called without any tracing subscriber installed and without any
enabled! guard (all guards move to the adapter).
- Existing traced-event tests continue to pass via the adapter.
- Linters and tests pass under
make test.
References
Background
Raised during review of PR #303 by @leynos.
Domain functions in
src/wrap/inline/andsrc/wrap/tokenize/currently import and use the vendor-specifictracingframework directly (#[tracing::instrument],debug!,trace!,tracing::enabled!). This couples infrastructure concerns to domain logic, making the domain harder to test without a tracing subscriber and harder to migrate to a different observability backend in the future.Required work
enum ClassificationEvent— that capture the observable outcomes of classification and parsing decisions without referencing any external crate.classify_fragment_kind,parse_link_or_image,find_footnote_end, the footnote predicate helpers) to accept an optional observer (e.g. a callback or a trait object implementing anObservertrait) and emit domain events through it, rather than emitting tracing calls inline.tracing-backed adapter that translatesClassificationEventvalues into the appropriatedebug!/trace!calls. Wire this adapter at the library boundary so existing instrumented behaviour is preserved.tracingimports from all domain modules; retain the dependency only in the adapter layer and in[dev-dependencies]for tests.Acceptance criteria
use tracing::import appears inside domain modules (src/wrap/inline/,src/wrap/tokenize/).enabled!guard (all guards move to the adapter).make test.References