MCPcopy Create free account
hub / github.com/apache/datafusion / trace_future

Function trace_future

datafusion/common-runtime/src/trace_utils.rs:130–152  ·  view source on GitHub ↗

Optionally instruments a future with custom tracing. If a tracer has been injected via `set_tracer`, the future's output is boxed (erasing its type), passed to the tracer, and then downcast back to the expected type. If no tracer is set, the original future is returned. # Type Parameters `T` - The concrete output type of the future. `F` - The future type. # Parameters `future` - The future to p

(future: F)

Source from the content-addressed store, hash-verified

128/// # Parameters
129/// * `future` - The future to potentially instrument.
130pub fn trace_future<T, F>(future: F) -> BoxFuture<'static, T>
131where
132 F: Future<Output = T> + Send + 'static,
133 T: Send + 'static,
134{
135 // Erase the future’s output type first:
136 let erased_future = async move {
137 let result = future.await;
138 Box::new(result) as Box<dyn Any + Send>
139 }
140 .boxed();
141
142 // Forward through the global tracer:
143 get_tracer()
144 .trace_future(erased_future)
145 // Downcast from `Box<dyn Any + Send>` back to `T`:
146 .map(|any_box| {
147 *any_box
148 .downcast::<T>()
149 .expect("Tracer must preserve the future’s output type!")
150 })
151 .boxed()
152}
153
154/// Optionally instruments a blocking closure with custom tracing.
155///

Callers 3

spawnMethod · 0.85
spawnMethod · 0.85
spawn_onMethod · 0.85

Calls 4

newFunction · 0.85
get_tracerFunction · 0.85
mapMethod · 0.45
trace_futureMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…