turbopack: move "compact database" tracing span to backend layer (#91693)
### What?
Move the `"compact database"` tracing span from `turbo-persistence`
(`db.rs`) to the backend layer
(`turbo-tasks-backend/src/backend/mod.rs`), make it a root span, group
it with the sibling `"persist"` span under a shared `"background
snapshot"` root, and emit one span per compaction session rather than
one per iteration.
### Why?
The `compact()` function is called from the background persistence job,
which runs inside a `"persisting background job"` span (inherited via
`.in_current_span()` at task spawn time). Previously the `"compact
database"` span was a child of that ambient span, making it appear
nested under `"persisting background job"` in traces — inconsistent with
its sibling spans `"snapshot"` and `"persist"`, which are already
top-level root spans.
Moving the span to the backend call site and giving it an explicit
parent allows us to:
1. Detach it from the `"persisting background job"` ambient span.
2. Group it with the `"persist"` span under a shared `"background
snapshot"` root span so all snapshot + compaction work appears together
in trace viewers.
3. Keep `turbo-persistence` free of span-policy decisions (root vs.
child), which belong at the call site where the ambient span context is
known.
### How?
- Introduced a non-entered `background_span`
(`tracing::info_span!(parent: None, "background snapshot")`) as a shared
root for both the snapshot/persist work and the compaction loop.
- Passed `background_span.id()` as the `parent_span` argument to
`snapshot_and_persist`, so the `"snapshot"` and `"persist"` spans become
children of it.
- Inside the idle compaction loop, a child `"compact database"` span is
entered and dropped synchronously around each `compact()` call (not
across the `tokio::select!` await point).
- Moved the span creation outside the `MAX_IDLE_COMPACTION_PASSES` loop
so there is one `"compact database"` span per compaction session rather
than one per iteration.
- Removed the `tracing::info_span!("compact database")` span from
`turbo-persistence/src/db.rs` entirely.
- Downgraded the `"sync new files"` span from `info` to `trace` level
(noise reduction).
The non-entered `tracing::Span` is `Send`, so it can be safely held
across the `select!` await without triggering the `future cannot be sent
between threads safely` compile error that an `EnteredSpan` would cause.
---------
Co-authored-by:
Tobias Koppers <sokra@users.noreply.github.com>
Co-authored-by:
Claude <noreply@anthropic.com>
Showing
Please
register
or
sign in
to comment