Skip to content

Commit

Permalink
Preserve the tracing span in the EndpointDriver task
Browse files Browse the repository at this point in the history
The EndpointDriver is spawned in a task.  Unless the span is copied
into this task the current span is lost.

Copying the current span means any tracing calls inside the driver,
from e.g. a custom AsyncUdpSocket, are preserved in the span.  This
makes it easy to use different parent spans for different endpoints
and have log messages appear with their parent span.  Otherwise these
log messages are not attached to a span.
  • Loading branch information
flub authored and Ralith committed Jul 27, 2023
1 parent 89ff085 commit 532ba7d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions quinn/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use proto::{
};
use rustc_hash::FxHashMap;
use tokio::sync::{futures::Notified, mpsc, Notify};
use tracing::{Instrument, Span};
use udp::{RecvMeta, BATCH_SIZE};

use crate::{
Expand Down Expand Up @@ -114,11 +115,14 @@ impl Endpoint {
runtime.clone(),
);
let driver = EndpointDriver(rc.clone());
runtime.spawn(Box::pin(async {
if let Err(e) = driver.await {
tracing::error!("I/O error: {}", e);
runtime.spawn(Box::pin(
async {
if let Err(e) = driver.await {
tracing::error!("I/O error: {}", e);
}
}
}));
.instrument(Span::current()),
));
Ok(Self {
inner: rc,
default_client_config: None,
Expand Down

0 comments on commit 532ba7d

Please sign in to comment.