fix: propagate tracing context across async boundaries to prevent orphan spans#6528
Open
sinianluoye wants to merge 8 commits intolance-format:mainfrom
Open
fix: propagate tracing context across async boundaries to prevent orphan spans#6528sinianluoye wants to merge 8 commits intolance-format:mainfrom
sinianluoye wants to merge 8 commits intolance-format:mainfrom
Conversation
…han spans When Lance queries execute through NAPI or other external callers with distributed tracing enabled, many internal spans appear as disconnected root traces in backends like Tempo instead of nesting under the caller's span tree. Root causes: 1. `execute_plan()` did not wrap the DataFusion plan with `TracedExec`, so lazy plan nodes captured `Span::current()` at poll time (often `<none>`) instead of at plan creation time. 2. Numerous async boundaries (boxed futures, boxed streams, spawned tasks) did not propagate the current span, causing work on those boundaries to lose its parent context. Changes: - Add `TracedExec` wrapper in `execute_plan()` to capture and propagate the caller's span through lazy DataFusion plan execution - Register `LanceJoinSetTracer` via `set_join_set_tracer()` so DataFusion internal spawned tasks also carry the current span - Add `FutureTracingExt` trait (`future_in_current_span`, `boxed_in_current_span`, `boxed_in_span`) alongside the existing `StreamTracingExt` in lance-core - Add `spawn_in_current_span` / `spawn_in_span` helpers for `tokio::spawn` - Convert all tracing-sensitive execution paths to use these helpers: decoder, scheduler, fragment reader, scan, filtered read, take, FTS, pushdown scan, cache - Add 7 regression tests covering scan, FTS+filter, vector search, hybrid FTS+vector reranker, and local filesystem variants - Add tracing context propagation documentation Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
…ropagation SpawnedTask::spawn (from DataFusion) aborts its inner task when dropped, which is critical for scan cleanup — when a scan is abandoned, dropping the stream must abort running fragment reads so ScanScheduler instances can be freed. Our earlier change to spawn_in_current_span used a raw JoinHandle that does NOT abort on drop, causing 999 tasks to deadlock in test_scan_finishes_all_tasks. Restore SpawnedTask::spawn with .future_in_current_span() to get both abort-on-drop semantics AND proper tracing context propagation. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
The span guard in spawn_cpu was held across the oneshot send, creating a race where the caller could observe the span as "still active" after receiving the result. Scope the guard so it drops before the send. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Cover the previously untested TracedExec display/debug/with_new_children methods and LanceJoinSetTracer trace_future/trace_block methods to improve patch coverage from ~57% to ~95%+ in exec.rs. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
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
When Lance queries are executed through external callers (e.g. NAPI bindings) with distributed tracing enabled, many internal Rust spans appear as disconnected root traces in backends like Tempo instead of nesting under the caller's span tree.
Root causes:
execute_plan()did not wrap the DataFusion plan withTracedExec, so lazy plan nodes capturedSpan::current()at poll time (often<none>) instead of at plan creation time.Changes:
TracedExecwrapper inexecute_plan()to capture and propagate the caller's span through lazy DataFusion plan executionLanceJoinSetTracerviaset_join_set_tracer()so DataFusion's internal spawned tasks also carry the current spanFutureTracingExttrait (future_in_current_span,boxed_in_current_span,boxed_in_span) alongside the existingStreamTracingExtin lance-corespawn_in_current_span/spawn_in_spanhelpers fortokio::spawnTest plan
rust/lance/tests/query/tracing.rsusing aSpanTreeRecorderlayer that asserts every span is reachable from the test root (no orphans):cargo test -p lance --features slow_tests --test integration_tests query::tracing::— 7/7 passcargo fmt --all -- --check— cleancargo check -p lance --features slow_tests --tests— clean🤖 Generated with Claude Code