Kurtiscwright commented on code in PR #2467:
URL: https://github.com/apache/iceberg-rust/pull/2467#discussion_r3321053964
##########
crates/iceberg/src/runtime/mod.rs:
##########
@@ -137,6 +159,17 @@ impl Runtime {
}
}
+ /// Attach a [`RuntimeTracer`] to both IO and CPU handles.
+ ///
+ /// Every future or blocking closure spawned through this runtime will be
+ /// passed through the tracer, allowing callers to inject instrumentation
+ /// (e.g. tracing spans, metrics) without modifying spawn sites.
+ pub fn with_tracer(mut self, tracer: Arc<dyn RuntimeTracer>) -> Self {
+ self.io.tracer = Some(tracer.clone());
+ self.cpu.tracer = Some(tracer);
Review Comment:
Why is the io.tracer cloned, but the cpu tracer isn't?
##########
crates/iceberg/src/runtime/tracer.rs:
##########
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::any::Any;
+use std::future::Future;
+
+use futures::FutureExt;
+use futures::future::BoxFuture;
+
+/// A trait for injecting instrumentation into spawned tasks.
+///
+/// Implementations can wrap futures or blocking closures with tracing spans,
+/// metrics, or other observability hooks. The tracer receives type-erased
+/// values and must preserve the output without modification.
+pub trait RuntimeTracer: Send + Sync + 'static {
+ /// Wraps a type-erased future with instrumentation.
+ ///
+ /// The implementation must not alter the future's output value.
+ fn trace_future(
+ &self,
+ fut: BoxFuture<'static, Box<dyn Any + Send>>,
+ ) -> BoxFuture<'static, Box<dyn Any + Send>>;
+
+ /// Wraps a type-erased blocking closure with instrumentation.
+ ///
+ /// The implementation must not alter the closure's return value.
+ fn trace_block(
+ &self,
+ f: Box<dyn FnOnce() -> Box<dyn Any + Send> + Send>,
Review Comment:
Because this is blocking do we really need the `Send` trait?
##########
crates/iceberg/src/runtime/tracer.rs:
##########
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::any::Any;
+use std::future::Future;
+
+use futures::FutureExt;
+use futures::future::BoxFuture;
+
+/// A trait for injecting instrumentation into spawned tasks.
+///
+/// Implementations can wrap futures or blocking closures with tracing spans,
+/// metrics, or other observability hooks. The tracer receives type-erased
+/// values and must preserve the output without modification.
+pub trait RuntimeTracer: Send + Sync + 'static {
+ /// Wraps a type-erased future with instrumentation.
+ ///
+ /// The implementation must not alter the future's output value.
+ fn trace_future(
+ &self,
+ fut: BoxFuture<'static, Box<dyn Any + Send>>,
+ ) -> BoxFuture<'static, Box<dyn Any + Send>>;
+
+ /// Wraps a type-erased blocking closure with instrumentation.
+ ///
+ /// The implementation must not alter the closure's return value.
+ fn trace_block(
+ &self,
+ f: Box<dyn FnOnce() -> Box<dyn Any + Send> + Send>,
+ ) -> Box<dyn FnOnce() -> Box<dyn Any + Send> + Send>;
+}
+
+/// Wraps a concrete future with the tracer, handling type erasure and
+/// restoration internally.
+pub(crate) fn trace_future<T, F>(
+ tracer: &dyn RuntimeTracer,
+ future: F,
+) -> impl Future<Output = T> + Send + 'static
+where
+ F: Future<Output = T> + Send + 'static,
+ T: Send + 'static,
+{
+ let erased = async move { Box::new(future.await) as Box<dyn Any + Send>
}.boxed();
+
+ tracer.trace_future(erased).map(|any_box| {
+ *any_box
+ .downcast::<T>()
+ .expect("RuntimeTracer must preserve the future's output type")
+ })
+}
+
+/// Wraps a concrete blocking closure with the tracer, handling type erasure
and
+/// restoration internally.
+pub(crate) fn trace_block<T, F>(
+ tracer: &dyn RuntimeTracer,
+ f: F,
+) -> impl FnOnce() -> T + Send + 'static
+where
+ F: FnOnce() -> T + Send + 'static,
+ T: Send + 'static,
Review Comment:
Same as above why do we need `Send` when this is blocking?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]