Skip to content

refactor: carry Arc<TracingInfo> on WriteItem; drop WriteTask service_name#46

Merged
prestwich merged 4 commits into
mainfrom
prestwich/write-task-tracing-info
Apr 22, 2026
Merged

refactor: carry Arc<TracingInfo> on WriteItem; drop WriteTask service_name#46
prestwich merged 4 commits into
mainfrom
prestwich/write-task-tracing-info

Conversation

@prestwich
Copy link
Copy Markdown
Member

Summary

  • Reverts the per-call-site service_name: &'static str threading that PR chore: downgrade per-message log to trace #45 added to WriteTask. The write task now reads the service label and per-request span off an Arc<TracingInfo> carried on each WriteItem, so the ajj.router.message_size_bytes histogram is still emitted with the correct service label.
  • HandlerCtx.tracing becomes Arc<TracingInfo>. WriteItem, NotifyPermit, and OwnedNotifyPermit carry Arc<TracingInfo> in place of a bare tracing::Span. Permit-based sends move the Arc into the WriteItem; HandlerCtx::notify and the response path do Arc::clone (refcount bump — parity with the prior Span::clone).
  • Final commit cleans up latent --no-default-features build breakage unrelated to this refactor but exposed once things were being touched: relocates WriteItem to routes/ctx.rs, gates tokio_stream-using methods behind pubsub, and adds #[cfg] gates / intra-doc link fixes to silence dead-code / broken-link diagnostics.

Minor breaking change

Three pub const fn methods lose their const qualifier because Arc deref is not available in const contexts on stable:

  • HandlerCtx::tracing_info
  • HandlerCtx::service_name
  • HandlerArgs::service_name

Signatures are otherwise unchanged. Warrants a minor-version bump on the next release.

Commits

  • 003db71 — expose TracingInfo::request_span to crate
  • f227836 — store TracingInfo in Arc on HandlerCtx
  • 2e4eb6c — carry Arc<TracingInfo> on WriteItem; drop WriteTask service_name
  • 6bedcfc — make --no-default-features build clean

Each commit compiles independently (bisect-safe).

Test plan

  • cargo +nightly fmt -- --check
  • cargo clippy -p ajj --all-features --all-targets -- -D warnings
  • cargo clippy -p ajj --all-features --lib -- -D warnings
  • cargo clippy -p ajj --no-default-features --all-targets -- -D warnings
  • cargo clippy -p ajj --no-default-features --lib -- -D warnings
  • cargo t -p ajj --all-features (48 tests pass)
  • RUSTDOCFLAGS="-D warnings" cargo doc -p ajj --no-deps (default, --all-features, and --no-default-features all clean)

🤖 Generated with Claude Code

prestwich and others added 4 commits April 19, 2026 14:37
HandlerCtx.tracing becomes Arc<TracingInfo> so the same tracing state
can be shared with WriteItems without repeated cloning. HandlerCtx::new
callers (axum and pubsub) now pass Arc<TracingInfo>.

HandlerCtx::tracing_info, HandlerCtx::service_name, and
HandlerArgs::service_name lose their `const` qualifier because Arc
deref is not `const` on stable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
WriteItem, NotifyPermit, and OwnedNotifyPermit now carry
Arc<TracingInfo> in place of tracing::Span. WriteTask::task_future
reads the service label and request span off the shared TracingInfo,
so the service_name field threaded through in #45 is no longer needed
and has been removed from WriteTask.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Relocate WriteItem from src/pubsub/shared.rs (pubsub-gated) to
src/routes/ctx.rs so it is visible without the pubsub feature, and
gate the two notification methods that depend on tokio_stream
(HandlerCtx::notify_stream, HandlerCtx::spawn_notify_stream) behind
#[cfg(feature = "pubsub")]. The other notification APIs (notify,
permit*) remain unconditional; without pubsub they are harmless
no-ops.

Additional #[cfg] gates to silence dead-code / unused-import lints
exposed now that the lib actually compiles without features:

- message_event! macro + record_message_size + message_size behind
  any(axum, pubsub)
- metrics::{histogram, Histogram} imports behind any(axum, pubsub)
- HandlerCtx::new gets allow(dead_code) when both axum and pubsub
  are off (nothing can construct a HandlerCtx)
- WriteItem struct gets allow(dead_code) without pubsub (no reader)

Replace two intra-doc links whose targets are feature-gated
(pubsub::AxumWsCfg, pubsub::ajj_websocket in lib.rs; axum in
handler.rs) with inline code so rustdoc --no-default-features no
longer fails link resolution.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@prestwich prestwich requested review from Evalir and Fraser999 April 21, 2026 14:15
@Evalir Evalir changed the title refactor: carry Arc<TracingInfo> on WriteItem; drop WriteTask service_name refactor: carry Arc<TracingInfo> on WriteItem; drop WriteTask service_name Apr 21, 2026
Copy link
Copy Markdown
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude only had unuseful nits and i had none, lgtm

@prestwich prestwich merged commit 11ad311 into main Apr 22, 2026
7 checks passed
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.

2 participants