fix(tracing): replace span.enter() across .await with .instrument(span)#4795
Merged
Conversation
Under tokio's multi-thread scheduler, holding an EnterGuard (_guard from span.enter()) across an .await boundary causes spans to propagate to the wrong task. Replace all four remaining instances with the correct idiom. - accumulator.rs: move span creation outside async move block, apply .instrument(span) before Box::pin; eliminates erroneous Span::current().record() attribution after awaits - manager.rs: convert add_remote, add_remote_ephemeral, download_and_extract to #[tracing::instrument], removing manual span.enter() guards entirely Also add #[tracing::instrument] to ContextAssembler::gather (the only uninstrumented function in the context assembly hot path) so every per-turn assembler call appears in Perfetto/Jaeger traces. Closes #4787 Closes #4783
9328364 to
d7e4373
Compare
3 tasks
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
span.enter()across.awaitanti-pattern in 4 locations (accumulator.rs,manager.rs×3). HeldEnterGuardunder tokio multi-thread causes incorrect span propagation; replaced with.instrument(span)and#[tracing::instrument].#[tracing::instrument]toContextAssembler::gather(the last uninstrumented function in the context assembly hot path), completing mandatory span coverage.Changes
crates/zeph-core/src/agent/memcot/accumulator.rsasync move, apply.instrument(span)beforeBox::pin; fixSpan::current().record()attributioncrates/zeph-plugins/src/manager.rsadd_remote,add_remote_ephemeral,download_and_extractto#[tracing::instrument]crates/zeph-context/src/assembler.rs#[tracing::instrument(name = "context.assembler.gather", skip_all)]CHANGELOG.md[Unreleased]Fixed sectionTest plan
cargo +nightly fmt --check— cleancargo clippy -p zeph-core -p zeph-plugins -p zeph-context -- -D warnings— 0 warningscargo nextest run --workspace --lib --bins— 10454 passed, 0 failedspan.enter()inmanager.rsare in sync functions (safe)Follow-up
Impl-critic found 6 additional
span.enter()across.awaitinstances outside this PR's scope:fidelity.rs:712,agent/mod.rs:3722,agent_access_impl.rs:67,evaluator.rs:206,shadow_probe.rs:145,shadow_probe.rs:180. A follow-up P3 issue will be filed after merge.Closes #4787
Closes #4783