Skip to content

Commit 9be59a4

Browse files
authored
fix(layers/tracing): propagate spans to executor tasks (#7864)
Wrap the composed executor so futures spawned by the tracing layer inherit the caller's current tracing span. Fixes #7377
1 parent a128add commit 9be59a4

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎core/layers/tracing/src/lib.rs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ impl Layer for TracingLayer {
149149
let transport = HttpTransporter::new(TracingHttpTransport {
150150
inner: inner.http_transport().clone(),
151151
});
152-
inner.with_http_transport(transport)
152+
let executor = Executor::with(TracingExecutor {
153+
inner: inner.executor().clone().into_inner(),
154+
});
155+
156+
inner.with_http_transport(transport).with_executor(executor)
153157
}
154158
}
155159

@@ -176,6 +180,21 @@ impl HttpTransport for TracingHttpTransport {
176180
}
177181
}
178182

183+
struct TracingExecutor {
184+
inner: Arc<dyn Execute>,
185+
}
186+
187+
impl Execute for TracingExecutor {
188+
fn execute(&self, f: BoxedStaticFuture<()>) {
189+
self.inner
190+
.execute(Box::pin(f.instrument(Span::current())) as BoxedStaticFuture<()>)
191+
}
192+
193+
fn timeout(&self) -> Option<BoxedStaticFuture<()>> {
194+
self.inner.timeout()
195+
}
196+
}
197+
179198
struct TracingStream<S> {
180199
inner: S,
181200
span: Span,

0 commit comments

Comments
 (0)