Skip to content

Commit 7c9a874

Browse files
authored
fix: Unparent connection span (#868)
The `Connection` struct contains a `tracing::Span` tracking its lifetime. This can be useful. The problem is that this span has as its parent the span within which the connection is created, meaning that it keeps that span alive (not closed) while it is alive. In practice that means, for example, instrumented functions that create connections and store those connections for reuse will not have their spans closed and exported when they end. This commit sets the `Connection`'s span's parent to `None` and gives it a "follows-from" relation to the span in which it was created instead. This shows the causal relationship between them, without tying the creating span's lifetime to the connection's lifetime.
1 parent c342e3f commit 7c9a874

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/proto/connection.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ where
126126
}
127127
}
128128
let streams = Streams::new(streams_config(&config));
129+
let span = tracing::debug_span!(parent: None, "Connection", peer = %P::NAME);
130+
span.follows_from(tracing::Span::current());
129131
Connection {
130132
codec,
131133
inner: ConnectionInner {
@@ -135,7 +137,7 @@ where
135137
ping_pong: PingPong::new(),
136138
settings: Settings::new(config.settings),
137139
streams,
138-
span: tracing::debug_span!("Connection", peer = %P::NAME),
140+
span,
139141
_phantom: PhantomData,
140142
},
141143
}

0 commit comments

Comments
 (0)