This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 4085a3b7a8 fix(layers/oteltrace): delegate executor submission and
timers (#8771)
4085a3b7a8 is described below
commit 4085a3b7a822ed3672a7c000af1aa58b3418d01c
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 08:55:05 2026 +0800
fix(layers/oteltrace): delegate executor submission and timers (#8771)
* fix(layers/oteltrace): delegate executor submission and timers
OtelTraceExecutor overrode only execute and timeout. Task submission calls
try_execute, so the default implementation fell through to inner.execute and
panicked on an unconfigured executor. TimeoutLayer also lost custom timers
because sleep defaulted to None.
Forward both methods with the same trace-context propagation as execute,
and add regression tests for fallible submission, timer delegation, and
try_execute context propagation.
* test(layers/oteltrace): distinguish execute from try_execute
Store tasks submitted through execute and try_execute separately so the
trace-context test fails if try_execute falls back to execute.
---
core/layers/oteltrace/src/lib.rs | 10 +++++
core/layers/oteltrace/src/tests.rs | 87 ++++++++++++++++++++++++++++++++++++--
2 files changed, 94 insertions(+), 3 deletions(-)
diff --git a/core/layers/oteltrace/src/lib.rs b/core/layers/oteltrace/src/lib.rs
index f225bcf6cb..ade7edee74 100644
--- a/core/layers/oteltrace/src/lib.rs
+++ b/core/layers/oteltrace/src/lib.rs
@@ -20,6 +20,7 @@
#![cfg_attr(docsrs, doc(auto_cfg))]
#![deny(missing_docs)]
use std::sync::Arc;
+use std::time::Duration;
use opendal_core::raw::*;
use opendal_core::*;
@@ -130,9 +131,18 @@ impl Execute for OtelTraceExecutor {
self.inner.execute(Box::pin(task.with_current_context()));
}
+ fn try_execute(&self, task: BoxedStaticFuture<()>) -> Result<()> {
+ self.inner
+ .try_execute(Box::pin(task.with_current_context()))
+ }
+
fn timeout(&self) -> Option<BoxedStaticFuture<()>> {
self.inner.timeout()
}
+
+ fn sleep(&self, duration: Duration) -> Option<BoxedStaticFuture<()>> {
+ self.inner.sleep(duration)
+ }
}
#[doc(hidden)]
diff --git a/core/layers/oteltrace/src/tests.rs
b/core/layers/oteltrace/src/tests.rs
index ca617ccb34..3420ebd699 100644
--- a/core/layers/oteltrace/src/tests.rs
+++ b/core/layers/oteltrace/src/tests.rs
@@ -18,6 +18,7 @@
use std::future;
use std::iter;
use std::sync::Mutex;
+use std::time::Duration;
use futures::stream;
use opendal_service_http::Http;
@@ -216,17 +217,93 @@ fn records_deleter_failures_without_changing_errors() {
#[derive(Clone, Default)]
struct QueuedExecutor {
- task: Arc<Mutex<Option<BoxedStaticFuture<()>>>>,
+ executed_task: Arc<Mutex<Option<BoxedStaticFuture<()>>>>,
+ submitted_task: Arc<Mutex<Option<BoxedStaticFuture<()>>>>,
}
impl Execute for QueuedExecutor {
fn execute(&self, task: BoxedStaticFuture<()>) {
- *self.task.lock().unwrap() = Some(task);
+ *self.executed_task.lock().unwrap() = Some(task);
+ }
+
+ fn try_execute(&self, task: BoxedStaticFuture<()>) -> Result<()> {
+ *self.submitted_task.lock().unwrap() = Some(task);
+ Ok(())
}
fn timeout(&self) -> Option<BoxedStaticFuture<()>> {
Some(Box::pin(future::ready(())))
}
+
+ fn sleep(&self, _duration: Duration) -> Option<BoxedStaticFuture<()>> {
+ Some(Box::pin(future::ready(())))
+ }
+}
+
+#[test]
+fn executor_delegates_fallible_submission_to_inner_executor() {
+ let context =
OperationContext::default().with_executor(Executor::with(()));
+ let context = OtelTraceLayer::new().apply_context(Arc::new(()), context);
+
+ let err = context
+ .executor()
+ .inner()
+ .try_execute(Box::pin(async {}))
+ .expect_err("an unconfigured executor must reject the task");
+ assert_eq!(err.kind(), ErrorKind::Unexpected);
+}
+
+#[test]
+fn executor_delegates_sleep_to_inner_executor() {
+ let context =
+
OperationContext::default().with_executor(Executor::with(QueuedExecutor::default()));
+ let context = OtelTraceLayer::new().apply_context(Arc::new(()), context);
+
+ assert!(
+ context
+ .executor()
+ .inner()
+ .sleep(Duration::from_millis(1))
+ .is_some(),
+ "the inner executor provides timers"
+ );
+}
+
+#[tokio::test]
+async fn executor_try_execute_propagates_submission_context_to_task() {
+ let inner = QueuedExecutor::default();
+ let context =
OperationContext::default().with_executor(Executor::with(inner.clone()));
+ let op = Operator::new(services::Memory::default())
+ .unwrap()
+ .with_context(context)
+ .layer(OtelTraceLayer::new());
+ let executor = op.context().executor().clone().into_inner();
+
+ let provider = SdkTracerProvider::builder().build();
+ let tracer = provider.tracer("test");
+ {
+ let parent = TraceContext::current_with_span(tracer.start("parent"));
+ let expected = parent.span().span_context().clone();
+ let _guard = parent.attach();
+ executor
+ .try_execute(Box::pin(async move {
+ let current = TraceContext::current();
+ assert_eq!(*current.span().span_context(), expected);
+ }))
+ .unwrap();
+ }
+
+ let task = inner
+ .submitted_task
+ .lock()
+ .unwrap()
+ .take()
+ .expect("try_execute should be delegated directly");
+ assert!(
+ inner.executed_task.lock().unwrap().is_none(),
+ "try_execute must not fall back to execute"
+ );
+ task.await;
}
#[tokio::test]
@@ -251,7 +328,11 @@ async fn executor_propagates_submission_context_to_task() {
}));
}
- let task = inner.task.lock().unwrap().take().unwrap();
+ let task = inner.executed_task.lock().unwrap().take().unwrap();
+ assert!(
+ inner.submitted_task.lock().unwrap().is_none(),
+ "execute must not be delegated through try_execute"
+ );
task.await;
executor.timeout().unwrap().await;
}