start adding tracing spans to internals (#478)
We've adopted `tracing` for diagnostics, but currently, it is just being used as a drop-in replacement for the `log` crate. Ideally, we would want to start emitting more structured diagnostics, using `tracing`'s `Span`s and structured key-value fields. A lot of the logging in `h2` is already written in a style that imitates the formatting of structured key-value logs, but as textual log messages. Migrating the logs to structured `tracing` events therefore is pretty easy to do. I've also started adding spans, mostly in the read path. Finally, I've updated the tests to use `tracing` rather than `env_logger`. The tracing setup happens in a macro, so that a span for each test with the test's name can be generated and entered. This will make the test output easier to read if multiple tests are run concurrently with `--nocapture`. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
@@ -149,6 +149,7 @@ use std::task::{Context, Poll};
|
||||
use std::time::Duration;
|
||||
use std::usize;
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
||||
use tracing_futures::Instrument;
|
||||
|
||||
/// Initializes new HTTP/2.0 streams on a connection by sending a request.
|
||||
///
|
||||
@@ -1115,7 +1116,10 @@ where
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
let builder = Builder::new();
|
||||
builder.handshake(io).await
|
||||
builder
|
||||
.handshake(io)
|
||||
.instrument(tracing::trace_span!("client_handshake", io = %std::any::type_name::<T>()))
|
||||
.await
|
||||
}
|
||||
|
||||
// ===== impl Connection =====
|
||||
@@ -1438,6 +1442,8 @@ impl Peer {
|
||||
impl proto::Peer for Peer {
|
||||
type Poll = Response<()>;
|
||||
|
||||
const NAME: &'static str = "Client";
|
||||
|
||||
fn r#dyn() -> proto::DynPeer {
|
||||
proto::DynPeer::Client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user