Skip to content

Commit 3df9e43

Browse files
authored
fix(observability): do not hold span guards across await points (#25482)
* add clippy rule * remove span.enter from topology builders * fix internal_logs source unit test holding a span guard across an await. The test still works because tokio:: test runs single-threaded by default, but better fixing it than silencing the clippy error * add changelog * apply suggestion
1 parent 2084d53 commit 3df9e43

4 files changed

Lines changed: 411 additions & 362 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Fixed a bug in the topology builder causing component metrics registered at build
2+
time to miss the component tags if the component build function awaits non-trivially.
3+
4+
This notably affected sinks using a disk buffer, and source or sinks performing
5+
IO work in the build function.
6+
7+
authors: gwenaskell

clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ disallowed-types = [
2020
{ path = "once_cell::sync::Lazy", reason = "Use `std::sync::LazyLock` instead." },
2121
{ path = "once_cell::unsync::Lazy", reason = "Use `std::sync::LazyCell` instead." },
2222
]
23+
24+
25+
await-holding-invalid-types = [
26+
{ path = "tracing::span::Entered", reason = "Holding a tracing span guard across an `.await` is thread-local and silently breaks when the task resumes on a different thread. Use `#[tracing::instrument]`, `future.instrument(span)`, or `Span::in_scope(|| ...)` instead." },
27+
]

src/sources/internal_logs.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ mod tests {
256256
component_id = "foo",
257257
component_type = "internal_logs",
258258
);
259-
let _enter = span.enter();
259+
let enter = span.enter();
260260

261261
error!(message = "Before source started.", %test_id);
262262

263+
drop(enter); // don't hold the span guard across an await point
264+
263265
let rx = start_source().await;
264266

267+
let enter = span.enter();
268+
265269
error!(message = "After source started.", %test_id);
266270

267271
{
@@ -276,6 +280,8 @@ mod tests {
276280
error!(message = "In a nested span.", %test_id);
277281
}
278282

283+
drop(enter);
284+
279285
sleep(Duration::from_millis(1)).await;
280286
let mut events = collect_ready(rx).await;
281287
let test_id = Value::from(test_id.to_string());

0 commit comments

Comments
 (0)