From 98db57d3e29f61f9955be1c98da0430b3aee8324 Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 21:12:37 +0200 Subject: [PATCH 01/10] add tracing instrumentation --- h3-quinn/Cargo.toml | 1 + h3-quinn/src/lib.rs | 20 ++++++++++++++++++++ h3/src/client/connection.rs | 6 +++++- h3/src/client/stream.rs | 8 ++++++++ h3/src/connection.rs | 23 +++++++++++++++++++++-- h3/src/server/connection.rs | 14 +++++++++++++- h3/src/server/request.rs | 2 ++ h3/src/server/stream.rs | 6 +++++- 8 files changed, 75 insertions(+), 5 deletions(-) diff --git a/h3-quinn/Cargo.toml b/h3-quinn/Cargo.toml index aade3fdb..1b5f66fa 100644 --- a/h3-quinn/Cargo.toml +++ b/h3-quinn/Cargo.toml @@ -21,3 +21,4 @@ quinn = { version = "0.11", default-features = false, features = [ tokio-util = { version = "0.7.9" } futures = { version = "0.3.28" } tokio = { version = "1", features = ["io-util"], default-features = false } +tracing = "0.1.40" diff --git a/h3-quinn/src/lib.rs b/h3-quinn/src/lib.rs index 7819b383..c0e791cd 100644 --- a/h3-quinn/src/lib.rs +++ b/h3-quinn/src/lib.rs @@ -27,6 +27,7 @@ use h3::{ quic::{self, Error, StreamId, WriteBuf}, }; use tokio_util::sync::ReusableBoxFuture; +use tracing::instrument; /// A QUIC connection backed by Quinn /// @@ -155,6 +156,7 @@ where type OpenStreams = OpenStreams; type AcceptError = ConnectionError; + #[instrument(skip_all)] fn poll_accept_bidi( &mut self, cx: &mut task::Context<'_>, @@ -169,6 +171,7 @@ where }))) } + #[instrument(skip_all)] fn poll_accept_recv( &mut self, cx: &mut task::Context<'_>, @@ -197,6 +200,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; + #[instrument(skip_all)] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -215,6 +219,7 @@ where })) } + #[instrument(skip_all)] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -229,6 +234,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } + #[instrument(skip_all)] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -243,6 +249,7 @@ where { type Error = SendDatagramError; + #[instrument(skip_all)] fn send_datagram(&mut self, data: Datagram) -> Result<(), SendDatagramError> { // TODO investigate static buffer from known max datagram size let mut buf = BytesMut::new(); @@ -259,6 +266,7 @@ impl quic::RecvDatagramExt for Connection { type Error = ConnectionError; #[inline] + #[instrument(skip_all)] fn poll_accept_datagram( &mut self, cx: &mut task::Context<'_>, @@ -289,6 +297,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; + #[instrument(skip_all)] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -307,6 +316,7 @@ where })) } + #[instrument(skip_all)] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -321,6 +331,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } + #[instrument(skip_all)] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -452,6 +463,7 @@ impl quic::RecvStream for RecvStream { type Buf = Bytes; type Error = ReadError; + #[instrument(skip_all)] fn poll_data( &mut self, cx: &mut task::Context<'_>, @@ -468,6 +480,7 @@ impl quic::RecvStream for RecvStream { Poll::Ready(Ok(chunk?.map(|c| c.bytes))) } + #[instrument(skip_all)] fn stop_sending(&mut self, error_code: u64) { self.stream .as_mut() @@ -476,6 +489,7 @@ impl quic::RecvStream for RecvStream { .ok(); } + #[instrument(skip_all)] fn recv_id(&self) -> StreamId { self.stream .as_ref() @@ -573,6 +587,7 @@ where { type Error = SendStreamError; + #[instrument(skip_all)] fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { if let Some(ref mut data) = self.writing { while data.has_remaining() { @@ -598,10 +613,12 @@ where Poll::Ready(Ok(())) } + #[instrument(skip_all)] fn poll_finish(&mut self, _cx: &mut task::Context<'_>) -> Poll> { Poll::Ready(self.stream.as_mut().unwrap().finish().map_err(|e| e.into())) } + #[instrument(skip_all)] fn reset(&mut self, reset_code: u64) { let _ = self .stream @@ -610,6 +627,7 @@ where .reset(VarInt::from_u64(reset_code).unwrap_or(VarInt::MAX)); } + #[instrument(skip_all)] fn send_data>>(&mut self, data: D) -> Result<(), Self::Error> { if self.writing.is_some() { return Err(Self::Error::NotReady); @@ -618,6 +636,7 @@ where Ok(()) } + #[instrument(skip_all)] fn send_id(&self) -> StreamId { self.stream .as_ref() @@ -633,6 +652,7 @@ impl quic::SendStreamUnframed for SendStream where B: Buf, { + #[instrument(skip_all)] fn poll_send( &mut self, cx: &mut task::Context<'_>, diff --git a/h3/src/client/connection.rs b/h3/src/client/connection.rs index 7fb591e9..6b095752 100644 --- a/h3/src/client/connection.rs +++ b/h3/src/client/connection.rs @@ -9,7 +9,7 @@ use std::{ use bytes::{Buf, BytesMut}; use futures_util::future; use http::request; -use tracing::{info, trace}; +use tracing::{info, instrument, trace}; use crate::{ connection::{self, ConnectionInner, ConnectionState, SharedStateRef}, @@ -121,6 +121,7 @@ where B: Buf, { /// Send an HTTP/3 request to the server + #[instrument(skip_all)] pub async fn send_request( &mut self, req: http::Request<()>, @@ -346,17 +347,20 @@ where B: Buf, { /// Initiate a graceful shutdown, accepting `max_push` potentially in-flight server pushes + #[instrument(skip_all)] pub async fn shutdown(&mut self, _max_push: usize) -> Result<(), Error> { // TODO: Calculate remaining pushes once server push is implemented. self.inner.shutdown(&mut self.sent_closing, PushId(0)).await } /// Wait until the connection is closed + #[instrument(skip_all)] pub async fn wait_idle(&mut self) -> Result<(), Error> { future::poll_fn(|cx| self.poll_close(cx)).await } /// Maintain the connection state until it is closed + #[instrument(skip_all)] pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { while let Poll::Ready(result) = self.inner.poll_control(cx) { match result { diff --git a/h3/src/client/stream.rs b/h3/src/client/stream.rs index e2b4b8e6..27a76d97 100644 --- a/h3/src/client/stream.rs +++ b/h3/src/client/stream.rs @@ -1,6 +1,7 @@ use bytes::Buf; use futures_util::future; use http::{HeaderMap, Response}; +use tracing::instrument; use crate::{ connection::{self, ConnectionState, SharedStateRef}, @@ -82,6 +83,7 @@ where /// This should be called before trying to receive any data with [`recv_data()`]. /// /// [`recv_data()`]: #method.recv_data + #[instrument(skip_all)] pub async fn recv_response(&mut self) -> Result, Error> { let mut frame = future::poll_fn(|cx| self.inner.stream.poll_next(cx)) .await @@ -141,11 +143,13 @@ where /// Receive some of the request body. // TODO what if called before recv_response ? + #[instrument(skip_all)] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Receive an optional set of trailers for the response. + #[instrument(skip_all)] pub async fn recv_trailers(&mut self) -> Result, Error> { let res = self.inner.recv_trailers().await; if let Err(ref e) = res { @@ -157,6 +161,7 @@ where } /// Tell the peer to stop sending into the underlying QUIC stream + #[instrument(skip_all)] pub fn stop_sending(&mut self, error_code: crate::error::Code) { // TODO take by value to prevent any further call as this request is cancelled // rename `cancel()` ? @@ -170,6 +175,7 @@ where B: Buf, { /// Send some data on the request body. + #[instrument(skip_all)] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { self.inner.send_data(buf).await } @@ -179,6 +185,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. + #[instrument(skip_all)] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { self.inner.send_trailers(trailers).await } @@ -188,6 +195,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. + #[instrument(skip_all)] pub async fn finish(&mut self) -> Result<(), Error> { self.inner.finish().await } diff --git a/h3/src/connection.rs b/h3/src/connection.rs index 5966eb87..09e78b85 100644 --- a/h3/src/connection.rs +++ b/h3/src/connection.rs @@ -9,7 +9,7 @@ use bytes::{Buf, Bytes, BytesMut}; use futures_util::{future, ready}; use http::HeaderMap; use stream::WriteBuf; -use tracing::warn; +use tracing::{instrument, warn}; use crate::{ config::{Config, Settings}, @@ -167,6 +167,7 @@ where B: Buf, { /// Sends the settings and initializes the control streams + #[instrument(skip_all)] pub async fn send_control_stream_headers(&mut self) -> Result<(), Error> { #[cfg(test)] if !self.config.send_settings { @@ -232,6 +233,7 @@ where } /// Initiates the connection and opens a control stream + #[instrument(skip_all)] pub async fn new(mut conn: C, shared: SharedStateRef, config: Config) -> Result { //= https://www.rfc-editor.org/rfc/rfc9114#section-6.2 //# Endpoints SHOULD create the HTTP control stream as well as the @@ -288,7 +290,7 @@ where } /// Send GOAWAY with specified max_id, iff max_id is smaller than the previous one. - + #[instrument(skip_all)] pub async fn shutdown( &mut self, sent_closing: &mut Option, @@ -317,6 +319,7 @@ where } #[allow(missing_docs)] + #[instrument(skip_all)] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -337,6 +340,7 @@ where /// Polls incoming streams /// /// Accepted streams which are not control, decoder, or encoder streams are buffer in `accepted_recv_streams` + #[instrument(skip_all)] pub fn poll_accept_recv(&mut self, cx: &mut Context<'_>) -> Result<(), Error> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Err(e.clone()); @@ -425,6 +429,7 @@ where } /// Waits for the control stream to be received and reads subsequent frames. + #[instrument(skip_all)] pub fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll, Error>> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Poll::Ready(Err(e.clone())); @@ -546,6 +551,7 @@ where Poll::Ready(res) } + #[instrument(skip_all)] pub(crate) fn process_goaway( &mut self, recv_closing: &mut Option, @@ -590,6 +596,7 @@ where /// Closes a Connection with code and reason. /// It returns an [`Error`] which can be returned. + #[instrument(skip_all)] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.shared.write("connection close err").error = Some(code.with_reason(reason.as_ref(), crate::error::ErrorLevel::ConnectionError)); @@ -598,6 +605,7 @@ where } // start grease stream and send data + #[instrument(skip_all)] fn poll_grease_stream(&mut self, cx: &mut Context<'_>) -> Poll<()> { if matches!(self.grease_step, GreaseStatus::NotStarted(_)) { self.grease_step = match self.conn.poll_open_send(cx) { @@ -682,6 +690,7 @@ where } #[allow(missing_docs)] + #[instrument(skip_all)] pub fn accepted_streams_mut(&mut self) -> &mut AcceptedStreams { &mut self.accepted_streams } @@ -725,6 +734,7 @@ where S: quic::RecvStream, { /// Receive some of the request body. + #[instrument(skip_all)] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -773,12 +783,15 @@ where .poll_data(cx) .map_err(|e| self.maybe_conn_err(e)) } + /// Receive some of the request body. + #[instrument(skip_all)] pub async fn recv_data(&mut self) -> Result, Error> { future::poll_fn(|cx| self.poll_recv_data(cx)).await } /// Receive trailers + #[instrument(skip_all)] pub async fn recv_trailers(&mut self) -> Result, Error> { let mut trailers = if let Some(encoded) = self.trailers.take() { encoded @@ -847,6 +860,7 @@ where } #[allow(missing_docs)] + #[instrument(skip_all)] pub fn stop_sending(&mut self, err_code: Code) { self.stream.stop_sending(err_code); } @@ -858,6 +872,7 @@ where B: Buf, { /// Send some data on the response body. + #[instrument(skip_all)] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { let frame = Frame::Data(buf); @@ -868,6 +883,7 @@ where } /// Send a set of trailers to end the request. + #[instrument(skip_all)] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { //= https://www.rfc-editor.org/rfc/rfc9114#section-4.2 //= type=TODO @@ -898,11 +914,13 @@ where } /// Stops a stream with an error code + #[instrument(skip_all)] pub fn stop_stream(&mut self, code: Code) { self.stream.reset(code.into()); } #[allow(missing_docs)] + #[instrument(skip_all)] pub async fn finish(&mut self) -> Result<(), Error> { if self.send_grease_frame { // send a grease frame once per Connection @@ -923,6 +941,7 @@ where S: quic::BidiStream, B: Buf, { + #[instrument(skip_all)] pub(crate) fn split( self, ) -> ( diff --git a/h3/src/server/connection.rs b/h3/src/server/connection.rs index 88d2d851..70169c8c 100644 --- a/h3/src/server/connection.rs +++ b/h3/src/server/connection.rs @@ -37,7 +37,7 @@ use crate::{ use crate::server::request::ResolveRequest; -use tracing::{trace, warn}; +use tracing::{instrument, trace, warn}; use super::stream::{ReadDatagram, RequestStream}; @@ -89,11 +89,13 @@ where /// Use a custom [`super::builder::Builder`] with [`super::builder::builder()`] to create a connection /// with different settings. /// Provide a Connection which implements [`quic::Connection`]. + #[instrument(skip_all)] pub async fn new(conn: C) -> Result { super::builder::builder().build(conn).await } /// Closes the connection with a code and a reason. + #[instrument(skip_all)] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.inner.close(code, reason) } @@ -109,6 +111,7 @@ where /// It returns a tuple with a [`http::Request`] and an [`RequestStream`]. /// The [`http::Request`] is the received request from the client. /// The [`RequestStream`] can be used to send the response. + #[instrument(skip_all)] pub async fn accept( &mut self, ) -> Result, RequestStream)>, Error> { @@ -154,6 +157,7 @@ where /// This is needed as a bidirectional stream may be read as part of incoming webtransport /// bi-streams. If it turns out that the stream is *not* a `WEBTRANSPORT_STREAM` the request /// may still want to be handled and passed to the user. + #[instrument(skip_all)] pub fn accept_with_frame( &mut self, mut stream: FrameStream, @@ -285,6 +289,7 @@ where /// Initiate a graceful shutdown, accepting `max_request` potentially still in-flight /// /// See [connection shutdown](https://www.rfc-editor.org/rfc/rfc9114.html#connection-shutdown) for more information. + #[instrument(skip_all)] pub async fn shutdown(&mut self, max_requests: usize) -> Result<(), Error> { let max_id = self .last_accepted_stream @@ -298,6 +303,7 @@ where /// /// This could be either a *Request* or a *WebTransportBiStream*, the first frame's type /// decides. + #[instrument(skip_all)] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -346,11 +352,13 @@ where } } + #[instrument(skip_all)] pub(crate) fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll> { while (self.poll_next_control(cx)?).is_ready() {} Poll::Pending } + #[instrument(skip_all)] pub(crate) fn poll_next_control( &mut self, cx: &mut Context<'_>, @@ -391,6 +399,7 @@ where Poll::Ready(Ok(frame)) } + #[instrument(skip_all)] fn poll_requests_completion(&mut self, cx: &mut Context<'_>) -> Poll<()> { loop { match self.request_end_recv.poll_recv(cx) { @@ -420,6 +429,7 @@ where B: Buf, { /// Sends a datagram + #[instrument(skip_all)] pub fn send_datagram(&mut self, stream_id: StreamId, data: B) -> Result<(), Error> { self.inner .conn @@ -436,6 +446,7 @@ where B: Buf, { /// Reads an incoming datagram + #[instrument(skip_all)] pub fn read_datagram(&mut self) -> ReadDatagram { ReadDatagram { conn: self, @@ -449,6 +460,7 @@ where C: quic::Connection, B: Buf, { + #[instrument(skip_all)] fn drop(&mut self) { self.inner.close(Code::H3_NO_ERROR, ""); } diff --git a/h3/src/server/request.rs b/h3/src/server/request.rs index 19c379d8..8743a555 100644 --- a/h3/src/server/request.rs +++ b/h3/src/server/request.rs @@ -2,6 +2,7 @@ use std::convert::TryFrom; use bytes::Buf; use http::{Request, StatusCode}; +use tracing::instrument; use crate::{error::Code, proto::headers::Header, qpack, quic, Error}; @@ -28,6 +29,7 @@ impl> ResolveRequest { } /// Finishes the resolution of the request + #[instrument(skip_all)] pub async fn resolve( mut self, ) -> Result<(Request<()>, RequestStream), Error> { diff --git a/h3/src/server/stream.rs b/h3/src/server/stream.rs index 610b83b6..a9725814 100644 --- a/h3/src/server/stream.rs +++ b/h3/src/server/stream.rs @@ -33,7 +33,7 @@ use crate::{ stream::{self}, }; -use tracing::error; +use tracing::{error, instrument}; /// Manage request and response transfer for an incoming request /// @@ -62,11 +62,13 @@ where B: Buf, { /// Receive data sent from the client + #[instrument(skip_all)] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Poll for data sent from the client + #[instrument(skip_all)] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -75,11 +77,13 @@ where } /// Receive an optional set of trailers for the request + #[instrument(skip_all)] pub async fn recv_trailers(&mut self) -> Result, Error> { self.inner.recv_trailers().await } /// Tell the peer to stop sending into the underlying QUIC stream + #[instrument(skip_all)] pub fn stop_sending(&mut self, error_code: crate::error::Code) { self.inner.stream.stop_sending(error_code) } From 87a75eeb55892029248d9d542e01013ed450d8d2 Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:11:18 +0200 Subject: [PATCH 02/10] add enable-tracing feature to h3-quinn --- h3-quinn/Cargo.toml | 5 ++++- h3-quinn/src/lib.rs | 40 +++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/h3-quinn/Cargo.toml b/h3-quinn/Cargo.toml index 1b5f66fa..9289b976 100644 --- a/h3-quinn/Cargo.toml +++ b/h3-quinn/Cargo.toml @@ -21,4 +21,7 @@ quinn = { version = "0.11", default-features = false, features = [ tokio-util = { version = "0.7.9" } futures = { version = "0.3.28" } tokio = { version = "1", features = ["io-util"], default-features = false } -tracing = "0.1.40" +tracing = { version = "0.1.40", optional = true } + +[features] +enable-tracing = ["tracing"] diff --git a/h3-quinn/src/lib.rs b/h3-quinn/src/lib.rs index c0e791cd..8f5a8356 100644 --- a/h3-quinn/src/lib.rs +++ b/h3-quinn/src/lib.rs @@ -27,6 +27,8 @@ use h3::{ quic::{self, Error, StreamId, WriteBuf}, }; use tokio_util::sync::ReusableBoxFuture; + +#[cfg(feature = "tracing")] use tracing::instrument; /// A QUIC connection backed by Quinn @@ -156,7 +158,7 @@ where type OpenStreams = OpenStreams; type AcceptError = ConnectionError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_accept_bidi( &mut self, cx: &mut task::Context<'_>, @@ -171,7 +173,7 @@ where }))) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_accept_recv( &mut self, cx: &mut task::Context<'_>, @@ -200,7 +202,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -219,7 +221,7 @@ where })) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -234,7 +236,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -249,7 +251,7 @@ where { type Error = SendDatagramError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn send_datagram(&mut self, data: Datagram) -> Result<(), SendDatagramError> { // TODO investigate static buffer from known max datagram size let mut buf = BytesMut::new(); @@ -266,7 +268,7 @@ impl quic::RecvDatagramExt for Connection { type Error = ConnectionError; #[inline] - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_accept_datagram( &mut self, cx: &mut task::Context<'_>, @@ -297,7 +299,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -316,7 +318,7 @@ where })) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -331,7 +333,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -463,7 +465,7 @@ impl quic::RecvStream for RecvStream { type Buf = Bytes; type Error = ReadError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_data( &mut self, cx: &mut task::Context<'_>, @@ -480,7 +482,7 @@ impl quic::RecvStream for RecvStream { Poll::Ready(Ok(chunk?.map(|c| c.bytes))) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn stop_sending(&mut self, error_code: u64) { self.stream .as_mut() @@ -489,7 +491,7 @@ impl quic::RecvStream for RecvStream { .ok(); } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn recv_id(&self) -> StreamId { self.stream .as_ref() @@ -587,7 +589,7 @@ where { type Error = SendStreamError; - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { if let Some(ref mut data) = self.writing { while data.has_remaining() { @@ -613,12 +615,12 @@ where Poll::Ready(Ok(())) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_finish(&mut self, _cx: &mut task::Context<'_>) -> Poll> { Poll::Ready(self.stream.as_mut().unwrap().finish().map_err(|e| e.into())) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn reset(&mut self, reset_code: u64) { let _ = self .stream @@ -627,7 +629,7 @@ where .reset(VarInt::from_u64(reset_code).unwrap_or(VarInt::MAX)); } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn send_data>>(&mut self, data: D) -> Result<(), Self::Error> { if self.writing.is_some() { return Err(Self::Error::NotReady); @@ -636,7 +638,7 @@ where Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn send_id(&self) -> StreamId { self.stream .as_ref() @@ -652,7 +654,7 @@ impl quic::SendStreamUnframed for SendStream where B: Buf, { - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_send( &mut self, cx: &mut task::Context<'_>, From 57fc4fb3b903cf4702cdf050aecf4edd5220959d Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:14:12 +0200 Subject: [PATCH 03/10] add enable-tracing feature to h3 --- h3/Cargo.toml | 3 ++- h3/src/client/connection.rs | 20 +++++++++----- h3/src/client/stream.rs | 15 ++++++----- h3/src/config.rs | 5 +++- h3/src/connection.rs | 53 ++++++++++++++++++++++++------------- h3/src/frame.rs | 8 ++++-- h3/src/proto/frame.rs | 12 +++++++-- h3/src/qpack/decoder.rs | 3 +++ h3/src/server/connection.rs | 38 +++++++++++++++----------- h3/src/server/request.rs | 7 ++++- h3/src/server/stream.rs | 16 ++++++----- 11 files changed, 120 insertions(+), 60 deletions(-) diff --git a/h3/Cargo.toml b/h3/Cargo.toml index 7475942a..90cd2c03 100644 --- a/h3/Cargo.toml +++ b/h3/Cargo.toml @@ -21,6 +21,7 @@ categories = [ [features] i-implement-a-third-party-backend-and-opt-into-breaking-changes = [] +enable-tracing = ["tracing"] [dependencies] bytes = "1" @@ -28,7 +29,7 @@ futures-util = { version = "0.3", default-features = false, features = ["io"] } http = "1" tokio = { version = "1", features = ["sync"] } pin-project-lite = { version = "0.2", default_features = false } -tracing = "0.1.40" +tracing = {version = "0.1.40", optional = true} fastrand = "2.0.1" [dev-dependencies] diff --git a/h3/src/client/connection.rs b/h3/src/client/connection.rs index 6b095752..20a8eeb6 100644 --- a/h3/src/client/connection.rs +++ b/h3/src/client/connection.rs @@ -9,6 +9,8 @@ use std::{ use bytes::{Buf, BytesMut}; use futures_util::future; use http::request; + +#[cfg(feature = "tracing")] use tracing::{info, instrument, trace}; use crate::{ @@ -121,7 +123,7 @@ where B: Buf, { /// Send an HTTP/3 request to the server - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_request( &mut self, req: http::Request<()>, @@ -347,20 +349,20 @@ where B: Buf, { /// Initiate a graceful shutdown, accepting `max_push` potentially in-flight server pushes - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn shutdown(&mut self, _max_push: usize) -> Result<(), Error> { // TODO: Calculate remaining pushes once server push is implemented. self.inner.shutdown(&mut self.sent_closing, PushId(0)).await } /// Wait until the connection is closed - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn wait_idle(&mut self) -> Result<(), Error> { future::poll_fn(|cx| self.poll_close(cx)).await } /// Maintain the connection state until it is closed - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { while let Poll::Ready(result) = self.inner.poll_control(cx) { match result { @@ -383,7 +385,12 @@ where //= type=TODO //# Once a server has provided new settings, //# clients MUST comply with those values. - Ok(Frame::Settings(_)) => trace!("Got settings"), + Ok(Frame::Settings(_)) => { + #[cfg(feature = "tracing")] + trace!("Got settings"); + () + } + Ok(Frame::Goaway(id)) => { //= https://www.rfc-editor.org/rfc/rfc9114#section-7.2.6 //# The GOAWAY frame is always sent on the control stream. In the @@ -398,7 +405,8 @@ where ))); } self.inner.process_goaway(&mut self.recv_closing, id)?; - + + #[cfg(feature = "tracing")] info!("Server initiated graceful shutdown, last: StreamId({})", id); } diff --git a/h3/src/client/stream.rs b/h3/src/client/stream.rs index 27a76d97..4287fdd8 100644 --- a/h3/src/client/stream.rs +++ b/h3/src/client/stream.rs @@ -1,6 +1,7 @@ use bytes::Buf; use futures_util::future; use http::{HeaderMap, Response}; +#[cfg(feature = "tracing")] use tracing::instrument; use crate::{ @@ -83,7 +84,7 @@ where /// This should be called before trying to receive any data with [`recv_data()`]. /// /// [`recv_data()`]: #method.recv_data - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_response(&mut self) -> Result, Error> { let mut frame = future::poll_fn(|cx| self.inner.stream.poll_next(cx)) .await @@ -143,13 +144,13 @@ where /// Receive some of the request body. // TODO what if called before recv_response ? - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Receive an optional set of trailers for the response. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { let res = self.inner.recv_trailers().await; if let Err(ref e) = res { @@ -161,7 +162,7 @@ where } /// Tell the peer to stop sending into the underlying QUIC stream - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, error_code: crate::error::Code) { // TODO take by value to prevent any further call as this request is cancelled // rename `cancel()` ? @@ -175,7 +176,7 @@ where B: Buf, { /// Send some data on the request body. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { self.inner.send_data(buf).await } @@ -185,7 +186,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { self.inner.send_trailers(trailers).await } @@ -195,7 +196,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn finish(&mut self) -> Result<(), Error> { self.inner.finish().await } diff --git a/h3/src/config.rs b/h3/src/config.rs index ffff248c..c2a6fe64 100644 --- a/h3/src/config.rs +++ b/h3/src/config.rs @@ -105,7 +105,10 @@ impl TryFrom for frame::Settings { //# H3_SETTINGS_ERROR. match settings.insert(frame::SettingId::grease(), 0) { Ok(_) => (), - Err(err) => tracing::warn!("Error when adding the grease Setting. Reason {}", err), + Err(_err) => { + #[cfg(feature = "tracing")] + tracing::warn!("Error when adding the grease Setting. Reason {}", _err); + } } } diff --git a/h3/src/connection.rs b/h3/src/connection.rs index 09e78b85..e27185ff 100644 --- a/h3/src/connection.rs +++ b/h3/src/connection.rs @@ -9,6 +9,8 @@ use bytes::{Buf, Bytes, BytesMut}; use futures_util::{future, ready}; use http::HeaderMap; use stream::WriteBuf; + +#[cfg(feature = "tracing")] use tracing::{instrument, warn}; use crate::{ @@ -167,7 +169,7 @@ where B: Buf, { /// Sends the settings and initializes the control streams - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_control_stream_headers(&mut self) -> Result<(), Error> { #[cfg(test)] if !self.config.send_settings { @@ -177,6 +179,7 @@ where let settings = frame::Settings::try_from(self.config) .map_err(|e| Code::H3_INTERNAL_ERROR.with_cause(e))?; + #[cfg(feature = "tracing")] tracing::debug!("Sending server settings: {:#x?}", settings); //= https://www.rfc-editor.org/rfc/rfc9114#section-3.2 @@ -233,7 +236,7 @@ where } /// Initiates the connection and opens a control stream - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn new(mut conn: C, shared: SharedStateRef, config: Config) -> Result { //= https://www.rfc-editor.org/rfc/rfc9114#section-6.2 //# Endpoints SHOULD create the HTTP control stream as well as the @@ -290,7 +293,7 @@ where } /// Send GOAWAY with specified max_id, iff max_id is smaller than the previous one. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn shutdown( &mut self, sent_closing: &mut Option, @@ -319,7 +322,7 @@ where } #[allow(missing_docs)] - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -340,7 +343,7 @@ where /// Polls incoming streams /// /// Accepted streams which are not control, decoder, or encoder streams are buffer in `accepted_recv_streams` - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_accept_recv(&mut self, cx: &mut Context<'_>) -> Result<(), Error> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Err(e.clone()); @@ -429,7 +432,7 @@ where } /// Waits for the control stream to be received and reads subsequent frames. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll, Error>> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Poll::Ready(Err(e.clone())); @@ -551,7 +554,7 @@ where Poll::Ready(res) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub(crate) fn process_goaway( &mut self, recv_closing: &mut Option, @@ -596,7 +599,7 @@ where /// Closes a Connection with code and reason. /// It returns an [`Error`] which can be returned. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.shared.write("connection close err").error = Some(code.with_reason(reason.as_ref(), crate::error::ErrorLevel::ConnectionError)); @@ -605,7 +608,7 @@ where } // start grease stream and send data - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_grease_stream(&mut self, cx: &mut Context<'_>) -> Poll<()> { if matches!(self.grease_step, GreaseStatus::NotStarted(_)) { self.grease_step = match self.conn.poll_open_send(cx) { @@ -614,7 +617,10 @@ where // could not create grease stream // don't try again self.send_grease_stream_flag = false; + + #[cfg(feature = "tracing")] warn!("grease stream creation failed with"); + return Poll::Ready(()); } Poll::Ready(Ok(stream)) => GreaseStatus::Started(Some(stream)), @@ -633,7 +639,10 @@ where .is_err() { self.send_grease_stream_flag = false; + + #[cfg(feature = "tracing")] warn!("write data on grease stream failed with"); + return Poll::Ready(()); }; } @@ -649,7 +658,10 @@ where // could not write grease frame // don't try again self.send_grease_stream_flag = false; + + #[cfg(feature = "tracing")] warn!("write data on grease stream failed with"); + return Poll::Ready(()); } }; @@ -676,7 +688,10 @@ where // could not finish grease stream // don't try again self.send_grease_stream_flag = false; + + #[cfg(feature = "tracing")] warn!("finish grease stream failed with"); + return Poll::Ready(()); } }; @@ -690,7 +705,7 @@ where } #[allow(missing_docs)] - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn accepted_streams_mut(&mut self) -> &mut AcceptedStreams { &mut self.accepted_streams } @@ -734,7 +749,7 @@ where S: quic::RecvStream, { /// Receive some of the request body. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -785,13 +800,13 @@ where } /// Receive some of the request body. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { future::poll_fn(|cx| self.poll_recv_data(cx)).await } /// Receive trailers - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { let mut trailers = if let Some(encoded) = self.trailers.take() { encoded @@ -860,7 +875,7 @@ where } #[allow(missing_docs)] - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, err_code: Code) { self.stream.stop_sending(err_code); } @@ -872,7 +887,7 @@ where B: Buf, { /// Send some data on the response body. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { let frame = Frame::Data(buf); @@ -883,7 +898,7 @@ where } /// Send a set of trailers to end the request. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { //= https://www.rfc-editor.org/rfc/rfc9114#section-4.2 //= type=TODO @@ -914,13 +929,13 @@ where } /// Stops a stream with an error code - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn stop_stream(&mut self, code: Code) { self.stream.reset(code.into()); } #[allow(missing_docs)] - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn finish(&mut self) -> Result<(), Error> { if self.send_grease_frame { // send a grease frame once per Connection @@ -941,7 +956,7 @@ where S: quic::BidiStream, B: Buf, { - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub(crate) fn split( self, ) -> ( diff --git a/h3/src/frame.rs b/h3/src/frame.rs index a166fa1b..fc3b7ef2 100644 --- a/h3/src/frame.rs +++ b/h3/src/frame.rs @@ -2,6 +2,7 @@ use std::task::{Context, Poll}; use bytes::Buf; +#[cfg(feature = "tracing")] use tracing::trace; use crate::stream::{BufRecvStream, WriteBuf}; @@ -227,8 +228,11 @@ impl FrameDecoder { }; match decoded { - Err(frame::FrameError::UnknownFrame(ty)) => { - trace!("ignore unknown frame type {:#x}", ty); + Err(frame::FrameError::UnknownFrame(_ty)) => { + + #[cfg(feature = "tracing")] + trace!("ignore unknown frame type {:#x}", _ty); + src.advance(pos); self.expected = None; continue; diff --git a/h3/src/proto/frame.rs b/h3/src/proto/frame.rs index fcebcd84..34d3770c 100644 --- a/h3/src/proto/frame.rs +++ b/h3/src/proto/frame.rs @@ -3,6 +3,7 @@ use std::{ convert::TryInto, fmt::{self, Debug}, }; +#[cfg(feature = "tracing")] use tracing::trace; use crate::webtransport::SessionId; @@ -86,7 +87,9 @@ impl Frame { // // See: https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.2 if ty == FrameType::WEBTRANSPORT_BI_STREAM { + #[cfg(feature = "tracing")] tracing::trace!("webtransport frame"); + return Ok(Frame::WebTransportStream(SessionId::decode(buf)?)); } @@ -103,7 +106,10 @@ impl Frame { } let mut payload = buf.take(len as usize); + + #[cfg(feature = "tracing")] trace!("frame ty: {:?}", ty); + let frame = match ty { FrameType::HEADERS => Ok(Frame::Headers(payload.copy_to_bytes(len as usize))), FrameType::SETTINGS => Ok(Frame::Settings(Settings::decode(&mut payload)?)), @@ -122,10 +128,11 @@ impl Frame { } }; - if let Ok(frame) = &frame { + if let Ok(_frame) = &frame { + #[cfg(feature = "tracing")] trace!( "got frame {:?}, len: {}, remaining: {}", - frame, + _frame, len, buf.remaining() ); @@ -536,6 +543,7 @@ impl Settings { //# H3_SETTINGS_ERROR. settings.insert(identifier, value)?; } else { + #[cfg(feature = "tracing")] tracing::debug!("Unsupported setting: {:#x?}", identifier); } } diff --git a/h3/src/qpack/decoder.rs b/h3/src/qpack/decoder.rs index 799002bc..9c7280fc 100644 --- a/h3/src/qpack/decoder.rs +++ b/h3/src/qpack/decoder.rs @@ -1,6 +1,7 @@ use bytes::{Buf, BufMut}; use std::{convert::TryInto, fmt, io::Cursor, num::TryFromIntError}; +#[cfg(feature = "tracing")] use tracing::trace; use super::{ @@ -118,7 +119,9 @@ impl Decoder { let inserted_on_start = self.table.total_inserted(); while let Some(instruction) = self.parse_instruction(read)? { + #[cfg(feature = "tracing")] trace!("instruction {:?}", instruction); + match instruction { Instruction::Insert(field) => self.table.put(field)?, Instruction::TableSizeUpdate(size) => { diff --git a/h3/src/server/connection.rs b/h3/src/server/connection.rs index 70169c8c..d1000e53 100644 --- a/h3/src/server/connection.rs +++ b/h3/src/server/connection.rs @@ -37,6 +37,7 @@ use crate::{ use crate::server::request::ResolveRequest; +#[cfg(feature = "tracing")] use tracing::{instrument, trace, warn}; use super::stream::{ReadDatagram, RequestStream}; @@ -89,13 +90,13 @@ where /// Use a custom [`super::builder::Builder`] with [`super::builder::builder()`] to create a connection /// with different settings. /// Provide a Connection which implements [`quic::Connection`]. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn new(conn: C) -> Result { super::builder::builder().build(conn).await } /// Closes the connection with a code and a reason. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.inner.close(code, reason) } @@ -111,7 +112,7 @@ where /// It returns a tuple with a [`http::Request`] and an [`RequestStream`]. /// The [`http::Request`] is the received request from the client. /// The [`RequestStream`] can be used to send the response. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn accept( &mut self, ) -> Result, RequestStream)>, Error> { @@ -157,7 +158,7 @@ where /// This is needed as a bidirectional stream may be read as part of incoming webtransport /// bi-streams. If it turns out that the stream is *not* a `WEBTRANSPORT_STREAM` the request /// may still want to be handled and passed to the user. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn accept_with_frame( &mut self, mut stream: FrameStream, @@ -289,7 +290,7 @@ where /// Initiate a graceful shutdown, accepting `max_request` potentially still in-flight /// /// See [connection shutdown](https://www.rfc-editor.org/rfc/rfc9114.html#connection-shutdown) for more information. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn shutdown(&mut self, max_requests: usize) -> Result<(), Error> { let max_id = self .last_accepted_stream @@ -303,7 +304,7 @@ where /// /// This could be either a *Request* or a *WebTransportBiStream*, the first frame's type /// decides. - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -352,13 +353,13 @@ where } } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub(crate) fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll> { while (self.poll_next_control(cx)?).is_ready() {} Poll::Pending } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub(crate) fn poll_next_control( &mut self, cx: &mut Context<'_>, @@ -366,10 +367,15 @@ where let frame = ready!(self.inner.poll_control(cx))?; match &frame { - Frame::Settings(w) => trace!("Got settings > {:?}", w), + Frame::Settings(_setting) => { + #[cfg(feature = "tracing")] + trace!("Got settings > {:?}", _setting); + () + }, &Frame::Goaway(id) => self.inner.process_goaway(&mut self.recv_closing, id)?, - f @ Frame::MaxPushId(_) | f @ Frame::CancelPush(_) => { - warn!("Control frame ignored {:?}", f); + _frame @ Frame::MaxPushId(_) | _frame @ Frame::CancelPush(_) => { + #[cfg(feature = "tracing")] + warn!("Control frame ignored {:?}", _frame); //= https://www.rfc-editor.org/rfc/rfc9114#section-7.2.3 //= type=TODO @@ -399,7 +405,7 @@ where Poll::Ready(Ok(frame)) } - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn poll_requests_completion(&mut self, cx: &mut Context<'_>) -> Poll<()> { loop { match self.request_end_recv.poll_recv(cx) { @@ -429,11 +435,13 @@ where B: Buf, { /// Sends a datagram - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn send_datagram(&mut self, stream_id: StreamId, data: B) -> Result<(), Error> { self.inner .conn .send_datagram(Datagram::new(stream_id, data))?; + + #[cfg(feature = "tracing")] tracing::info!("Sent datagram"); Ok(()) @@ -446,7 +454,7 @@ where B: Buf, { /// Reads an incoming datagram - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn read_datagram(&mut self) -> ReadDatagram { ReadDatagram { conn: self, @@ -460,7 +468,7 @@ where C: quic::Connection, B: Buf, { - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] fn drop(&mut self) { self.inner.close(Code::H3_NO_ERROR, ""); } diff --git a/h3/src/server/request.rs b/h3/src/server/request.rs index 8743a555..79454e35 100644 --- a/h3/src/server/request.rs +++ b/h3/src/server/request.rs @@ -2,6 +2,8 @@ use std::convert::TryFrom; use bytes::Buf; use http::{Request, StatusCode}; + +#[cfg(feature = "tracing")] use tracing::instrument; use crate::{error::Code, proto::headers::Header, qpack, quic, Error}; @@ -29,7 +31,7 @@ impl> ResolveRequest { } /// Finishes the resolution of the request - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn resolve( mut self, ) -> Result<(Request<()>, RequestStream), Error> { @@ -90,7 +92,10 @@ impl> ResolveRequest { *req.version_mut() = http::Version::HTTP_3; // send the grease frame only once // self.inner.send_grease_frame = false; + + #[cfg(feature = "tracing")] tracing::trace!("replying with: {:?}", req); + Ok((req, self.request_stream)) } } diff --git a/h3/src/server/stream.rs b/h3/src/server/stream.rs index a9725814..3f333903 100644 --- a/h3/src/server/stream.rs +++ b/h3/src/server/stream.rs @@ -33,6 +33,7 @@ use crate::{ stream::{self}, }; +#[cfg(feature = "tracing")] use tracing::{error, instrument}; /// Manage request and response transfer for an incoming request @@ -62,13 +63,13 @@ where B: Buf, { /// Receive data sent from the client - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Poll for data sent from the client - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -77,13 +78,13 @@ where } /// Receive an optional set of trailers for the request - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { self.inner.recv_trailers().await } /// Tell the peer to stop sending into the underlying QUIC stream - #[instrument(skip_all)] + #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, error_code: crate::error::Code) { self.inner.stream.stop_sending(error_code) } @@ -209,10 +210,11 @@ where impl Drop for RequestEnd { fn drop(&mut self) { - if let Err(e) = self.request_end.send(self.stream_id) { + if let Err(_error) = self.request_end.send(self.stream_id) { + #[cfg(feature = "tracing")] error!( "failed to notify connection of request end: {} {}", - self.stream_id, e + self.stream_id, _error ); } } @@ -238,7 +240,9 @@ where type Output = Result>, Error>; fn poll(mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + #[cfg(feature = "tracing")] tracing::trace!("poll: read_datagram"); + match ready!(self.conn.inner.conn.poll_accept_datagram(cx))? { Some(v) => Poll::Ready(Ok(Some(Datagram::decode(v)?))), None => Poll::Ready(Ok(None)), From 85002f311a0b0ae87d5cfaa494994367d3e9552c Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:26:03 +0200 Subject: [PATCH 04/10] try new CI workflow --- .github/workflows/CI.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8009e359..9f4db99b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -111,6 +111,11 @@ jobs: matrix: os: [ubuntu-latest] toolchain: [stable, beta] + include: + - features: i-implement-a-third-party-backend-and-opt-into-breaking-changes + - features: enable-tracing + - features: enable-tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -125,6 +130,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: test + args: --features ${{ matrix.features }} - name: h3Spec run: ./ci/h3spec.sh if: matrix.toolchain == 'stable' From 2658bfa393c8e7091bc0a3e44d5c85a2bf48f03d Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:26:52 +0200 Subject: [PATCH 05/10] add tracing to examples --- examples/Cargo.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 6cdf5feb..12af7760 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -10,8 +10,8 @@ edition = "2021" anyhow = "1.0" bytes = "1" futures = "0.3" -h3 = { path = "../h3" } -h3-quinn = { path = "../h3-quinn" } +h3 = { path = "../h3", features = ["enable-tracing"] } +h3-quinn = { path = "../h3-quinn", features = ["enable-tracing"] } h3-webtransport = { path = "../h3-webtransport" } http = "1" quinn = { version = "0.11", default-features = false, features = [ @@ -20,7 +20,11 @@ quinn = { version = "0.11", default-features = false, features = [ "ring", ] } rcgen = { version = "0.13" } -rustls = { version = "0.23", default-features = false, features = ["logging", "ring", "std"] } +rustls = { version = "0.23", default-features = false, features = [ + "logging", + "ring", + "std", +] } rustls-native-certs = "0.7" structopt = "0.3" tokio = { version = "1.27", features = ["full"] } From efbabbb46bdcf1513c8ccb3f4cb3c66cff991c55 Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:28:50 +0200 Subject: [PATCH 06/10] fmt --- h3/src/client/connection.rs | 2 +- h3/src/frame.rs | 1 - h3/src/qpack/decoder.rs | 2 +- h3/src/server/connection.rs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/h3/src/client/connection.rs b/h3/src/client/connection.rs index 20a8eeb6..647654f4 100644 --- a/h3/src/client/connection.rs +++ b/h3/src/client/connection.rs @@ -405,7 +405,7 @@ where ))); } self.inner.process_goaway(&mut self.recv_closing, id)?; - + #[cfg(feature = "tracing")] info!("Server initiated graceful shutdown, last: StreamId({})", id); } diff --git a/h3/src/frame.rs b/h3/src/frame.rs index fc3b7ef2..0a74137d 100644 --- a/h3/src/frame.rs +++ b/h3/src/frame.rs @@ -229,7 +229,6 @@ impl FrameDecoder { match decoded { Err(frame::FrameError::UnknownFrame(_ty)) => { - #[cfg(feature = "tracing")] trace!("ignore unknown frame type {:#x}", _ty); diff --git a/h3/src/qpack/decoder.rs b/h3/src/qpack/decoder.rs index 9c7280fc..10bddb41 100644 --- a/h3/src/qpack/decoder.rs +++ b/h3/src/qpack/decoder.rs @@ -121,7 +121,7 @@ impl Decoder { while let Some(instruction) = self.parse_instruction(read)? { #[cfg(feature = "tracing")] trace!("instruction {:?}", instruction); - + match instruction { Instruction::Insert(field) => self.table.put(field)?, Instruction::TableSizeUpdate(size) => { diff --git a/h3/src/server/connection.rs b/h3/src/server/connection.rs index d1000e53..847d5dbe 100644 --- a/h3/src/server/connection.rs +++ b/h3/src/server/connection.rs @@ -371,7 +371,7 @@ where #[cfg(feature = "tracing")] trace!("Got settings > {:?}", _setting); () - }, + } &Frame::Goaway(id) => self.inner.process_goaway(&mut self.recv_closing, id)?, _frame @ Frame::MaxPushId(_) | _frame @ Frame::CancelPush(_) => { #[cfg(feature = "tracing")] From eadb342fd5a28097087226491e16263030b8536c Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:36:41 +0200 Subject: [PATCH 07/10] matrix? --- .github/workflows/CI.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9f4db99b..a6e69174 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -111,11 +111,7 @@ jobs: matrix: os: [ubuntu-latest] toolchain: [stable, beta] - include: - - features: i-implement-a-third-party-backend-and-opt-into-breaking-changes - - features: enable-tracing - - features: enable-tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes - + features: [i-implement-a-third-party-backend-and-opt-into-breaking-changes, enable-tracing, 'enable-tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 From f4fe46eb162d22e3952ccaf3784b2e6b777a312b Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:54:30 +0200 Subject: [PATCH 08/10] rename features to avoid confusion --- h3-quinn/Cargo.toml | 2 +- h3-quinn/src/lib.rs | 40 ++++++++++++++--------------- h3/Cargo.toml | 2 +- h3/src/client/connection.rs | 14 +++++------ h3/src/client/stream.rs | 16 ++++++------ h3/src/config.rs | 2 +- h3/src/connection.rs | 50 ++++++++++++++++++------------------- h3/src/frame.rs | 4 +-- h3/src/proto/frame.rs | 10 ++++---- h3/src/qpack/decoder.rs | 4 +-- h3/src/server/connection.rs | 32 ++++++++++++------------ h3/src/server/request.rs | 6 ++--- h3/src/server/stream.rs | 14 +++++------ 13 files changed, 98 insertions(+), 98 deletions(-) diff --git a/h3-quinn/Cargo.toml b/h3-quinn/Cargo.toml index 9289b976..26a591b4 100644 --- a/h3-quinn/Cargo.toml +++ b/h3-quinn/Cargo.toml @@ -24,4 +24,4 @@ tokio = { version = "1", features = ["io-util"], default-features = false } tracing = { version = "0.1.40", optional = true } [features] -enable-tracing = ["tracing"] +h3-quinn-tracing = ["tracing"] diff --git a/h3-quinn/src/lib.rs b/h3-quinn/src/lib.rs index 8f5a8356..05441627 100644 --- a/h3-quinn/src/lib.rs +++ b/h3-quinn/src/lib.rs @@ -28,7 +28,7 @@ use h3::{ }; use tokio_util::sync::ReusableBoxFuture; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-quinn-tracing")] use tracing::instrument; /// A QUIC connection backed by Quinn @@ -158,7 +158,7 @@ where type OpenStreams = OpenStreams; type AcceptError = ConnectionError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_accept_bidi( &mut self, cx: &mut task::Context<'_>, @@ -173,7 +173,7 @@ where }))) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_accept_recv( &mut self, cx: &mut task::Context<'_>, @@ -202,7 +202,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -221,7 +221,7 @@ where })) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -236,7 +236,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -251,7 +251,7 @@ where { type Error = SendDatagramError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn send_datagram(&mut self, data: Datagram) -> Result<(), SendDatagramError> { // TODO investigate static buffer from known max datagram size let mut buf = BytesMut::new(); @@ -268,7 +268,7 @@ impl quic::RecvDatagramExt for Connection { type Error = ConnectionError; #[inline] - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_accept_datagram( &mut self, cx: &mut task::Context<'_>, @@ -299,7 +299,7 @@ where type BidiStream = BidiStream; type OpenError = ConnectionError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_open_bidi( &mut self, cx: &mut task::Context<'_>, @@ -318,7 +318,7 @@ where })) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_open_send( &mut self, cx: &mut task::Context<'_>, @@ -333,7 +333,7 @@ where Poll::Ready(Ok(Self::SendStream::new(send))) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn close(&mut self, code: h3::error::Code, reason: &[u8]) { self.conn.close( VarInt::from_u64(code.value()).expect("error code VarInt"), @@ -465,7 +465,7 @@ impl quic::RecvStream for RecvStream { type Buf = Bytes; type Error = ReadError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_data( &mut self, cx: &mut task::Context<'_>, @@ -482,7 +482,7 @@ impl quic::RecvStream for RecvStream { Poll::Ready(Ok(chunk?.map(|c| c.bytes))) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn stop_sending(&mut self, error_code: u64) { self.stream .as_mut() @@ -491,7 +491,7 @@ impl quic::RecvStream for RecvStream { .ok(); } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn recv_id(&self) -> StreamId { self.stream .as_ref() @@ -589,7 +589,7 @@ where { type Error = SendStreamError; - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { if let Some(ref mut data) = self.writing { while data.has_remaining() { @@ -615,12 +615,12 @@ where Poll::Ready(Ok(())) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_finish(&mut self, _cx: &mut task::Context<'_>) -> Poll> { Poll::Ready(self.stream.as_mut().unwrap().finish().map_err(|e| e.into())) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn reset(&mut self, reset_code: u64) { let _ = self .stream @@ -629,7 +629,7 @@ where .reset(VarInt::from_u64(reset_code).unwrap_or(VarInt::MAX)); } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn send_data>>(&mut self, data: D) -> Result<(), Self::Error> { if self.writing.is_some() { return Err(Self::Error::NotReady); @@ -638,7 +638,7 @@ where Ok(()) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn send_id(&self) -> StreamId { self.stream .as_ref() @@ -654,7 +654,7 @@ impl quic::SendStreamUnframed for SendStream where B: Buf, { - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))] fn poll_send( &mut self, cx: &mut task::Context<'_>, diff --git a/h3/Cargo.toml b/h3/Cargo.toml index 90cd2c03..04a94c57 100644 --- a/h3/Cargo.toml +++ b/h3/Cargo.toml @@ -21,7 +21,7 @@ categories = [ [features] i-implement-a-third-party-backend-and-opt-into-breaking-changes = [] -enable-tracing = ["tracing"] +h3-tracing = ["tracing"] [dependencies] bytes = "1" diff --git a/h3/src/client/connection.rs b/h3/src/client/connection.rs index 647654f4..d6bf946b 100644 --- a/h3/src/client/connection.rs +++ b/h3/src/client/connection.rs @@ -10,7 +10,7 @@ use bytes::{Buf, BytesMut}; use futures_util::future; use http::request; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::{info, instrument, trace}; use crate::{ @@ -123,7 +123,7 @@ where B: Buf, { /// Send an HTTP/3 request to the server - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_request( &mut self, req: http::Request<()>, @@ -349,20 +349,20 @@ where B: Buf, { /// Initiate a graceful shutdown, accepting `max_push` potentially in-flight server pushes - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn shutdown(&mut self, _max_push: usize) -> Result<(), Error> { // TODO: Calculate remaining pushes once server push is implemented. self.inner.shutdown(&mut self.sent_closing, PushId(0)).await } /// Wait until the connection is closed - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn wait_idle(&mut self) -> Result<(), Error> { future::poll_fn(|cx| self.poll_close(cx)).await } /// Maintain the connection state until it is closed - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { while let Poll::Ready(result) = self.inner.poll_control(cx) { match result { @@ -386,7 +386,7 @@ where //# Once a server has provided new settings, //# clients MUST comply with those values. Ok(Frame::Settings(_)) => { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!("Got settings"); () } @@ -406,7 +406,7 @@ where } self.inner.process_goaway(&mut self.recv_closing, id)?; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] info!("Server initiated graceful shutdown, last: StreamId({})", id); } diff --git a/h3/src/client/stream.rs b/h3/src/client/stream.rs index 4287fdd8..978de81e 100644 --- a/h3/src/client/stream.rs +++ b/h3/src/client/stream.rs @@ -1,7 +1,7 @@ use bytes::Buf; use futures_util::future; use http::{HeaderMap, Response}; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::instrument; use crate::{ @@ -84,7 +84,7 @@ where /// This should be called before trying to receive any data with [`recv_data()`]. /// /// [`recv_data()`]: #method.recv_data - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_response(&mut self) -> Result, Error> { let mut frame = future::poll_fn(|cx| self.inner.stream.poll_next(cx)) .await @@ -144,13 +144,13 @@ where /// Receive some of the request body. // TODO what if called before recv_response ? - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Receive an optional set of trailers for the response. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { let res = self.inner.recv_trailers().await; if let Err(ref e) = res { @@ -162,7 +162,7 @@ where } /// Tell the peer to stop sending into the underlying QUIC stream - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, error_code: crate::error::Code) { // TODO take by value to prevent any further call as this request is cancelled // rename `cancel()` ? @@ -176,7 +176,7 @@ where B: Buf, { /// Send some data on the request body. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { self.inner.send_data(buf).await } @@ -186,7 +186,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { self.inner.send_trailers(trailers).await } @@ -196,7 +196,7 @@ where /// Either [`RequestStream::finish`] or /// [`RequestStream::send_trailers`] must be called to finalize a /// request. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn finish(&mut self) -> Result<(), Error> { self.inner.finish().await } diff --git a/h3/src/config.rs b/h3/src/config.rs index c2a6fe64..1c1271f2 100644 --- a/h3/src/config.rs +++ b/h3/src/config.rs @@ -106,7 +106,7 @@ impl TryFrom for frame::Settings { match settings.insert(frame::SettingId::grease(), 0) { Ok(_) => (), Err(_err) => { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::warn!("Error when adding the grease Setting. Reason {}", _err); } } diff --git a/h3/src/connection.rs b/h3/src/connection.rs index e27185ff..43fa5d6f 100644 --- a/h3/src/connection.rs +++ b/h3/src/connection.rs @@ -10,7 +10,7 @@ use futures_util::{future, ready}; use http::HeaderMap; use stream::WriteBuf; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::{instrument, warn}; use crate::{ @@ -169,7 +169,7 @@ where B: Buf, { /// Sends the settings and initializes the control streams - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_control_stream_headers(&mut self) -> Result<(), Error> { #[cfg(test)] if !self.config.send_settings { @@ -179,7 +179,7 @@ where let settings = frame::Settings::try_from(self.config) .map_err(|e| Code::H3_INTERNAL_ERROR.with_cause(e))?; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::debug!("Sending server settings: {:#x?}", settings); //= https://www.rfc-editor.org/rfc/rfc9114#section-3.2 @@ -236,7 +236,7 @@ where } /// Initiates the connection and opens a control stream - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn new(mut conn: C, shared: SharedStateRef, config: Config) -> Result { //= https://www.rfc-editor.org/rfc/rfc9114#section-6.2 //# Endpoints SHOULD create the HTTP control stream as well as the @@ -293,7 +293,7 @@ where } /// Send GOAWAY with specified max_id, iff max_id is smaller than the previous one. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn shutdown( &mut self, sent_closing: &mut Option, @@ -322,7 +322,7 @@ where } #[allow(missing_docs)] - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -343,7 +343,7 @@ where /// Polls incoming streams /// /// Accepted streams which are not control, decoder, or encoder streams are buffer in `accepted_recv_streams` - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_accept_recv(&mut self, cx: &mut Context<'_>) -> Result<(), Error> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Err(e.clone()); @@ -432,7 +432,7 @@ where } /// Waits for the control stream to be received and reads subsequent frames. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll, Error>> { if let Some(ref e) = self.shared.read("poll_accept_request").error { return Poll::Ready(Err(e.clone())); @@ -554,7 +554,7 @@ where Poll::Ready(res) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub(crate) fn process_goaway( &mut self, recv_closing: &mut Option, @@ -599,7 +599,7 @@ where /// Closes a Connection with code and reason. /// It returns an [`Error`] which can be returned. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.shared.write("connection close err").error = Some(code.with_reason(reason.as_ref(), crate::error::ErrorLevel::ConnectionError)); @@ -608,7 +608,7 @@ where } // start grease stream and send data - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] fn poll_grease_stream(&mut self, cx: &mut Context<'_>) -> Poll<()> { if matches!(self.grease_step, GreaseStatus::NotStarted(_)) { self.grease_step = match self.conn.poll_open_send(cx) { @@ -618,7 +618,7 @@ where // don't try again self.send_grease_stream_flag = false; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] warn!("grease stream creation failed with"); return Poll::Ready(()); @@ -640,7 +640,7 @@ where { self.send_grease_stream_flag = false; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] warn!("write data on grease stream failed with"); return Poll::Ready(()); @@ -659,7 +659,7 @@ where // don't try again self.send_grease_stream_flag = false; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] warn!("write data on grease stream failed with"); return Poll::Ready(()); @@ -689,7 +689,7 @@ where // don't try again self.send_grease_stream_flag = false; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] warn!("finish grease stream failed with"); return Poll::Ready(()); @@ -705,7 +705,7 @@ where } #[allow(missing_docs)] - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn accepted_streams_mut(&mut self) -> &mut AcceptedStreams { &mut self.accepted_streams } @@ -749,7 +749,7 @@ where S: quic::RecvStream, { /// Receive some of the request body. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -800,13 +800,13 @@ where } /// Receive some of the request body. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { future::poll_fn(|cx| self.poll_recv_data(cx)).await } /// Receive trailers - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { let mut trailers = if let Some(encoded) = self.trailers.take() { encoded @@ -875,7 +875,7 @@ where } #[allow(missing_docs)] - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, err_code: Code) { self.stream.stop_sending(err_code); } @@ -887,7 +887,7 @@ where B: Buf, { /// Send some data on the response body. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_data(&mut self, buf: B) -> Result<(), Error> { let frame = Frame::Data(buf); @@ -898,7 +898,7 @@ where } /// Send a set of trailers to end the request. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> { //= https://www.rfc-editor.org/rfc/rfc9114#section-4.2 //= type=TODO @@ -929,13 +929,13 @@ where } /// Stops a stream with an error code - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn stop_stream(&mut self, code: Code) { self.stream.reset(code.into()); } #[allow(missing_docs)] - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn finish(&mut self) -> Result<(), Error> { if self.send_grease_frame { // send a grease frame once per Connection @@ -956,7 +956,7 @@ where S: quic::BidiStream, B: Buf, { - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub(crate) fn split( self, ) -> ( diff --git a/h3/src/frame.rs b/h3/src/frame.rs index 0a74137d..fac41b19 100644 --- a/h3/src/frame.rs +++ b/h3/src/frame.rs @@ -2,7 +2,7 @@ use std::task::{Context, Poll}; use bytes::Buf; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::trace; use crate::stream::{BufRecvStream, WriteBuf}; @@ -229,7 +229,7 @@ impl FrameDecoder { match decoded { Err(frame::FrameError::UnknownFrame(_ty)) => { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!("ignore unknown frame type {:#x}", _ty); src.advance(pos); diff --git a/h3/src/proto/frame.rs b/h3/src/proto/frame.rs index 34d3770c..20f9d9c2 100644 --- a/h3/src/proto/frame.rs +++ b/h3/src/proto/frame.rs @@ -3,7 +3,7 @@ use std::{ convert::TryInto, fmt::{self, Debug}, }; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::trace; use crate::webtransport::SessionId; @@ -87,7 +87,7 @@ impl Frame { // // See: https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.2 if ty == FrameType::WEBTRANSPORT_BI_STREAM { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::trace!("webtransport frame"); return Ok(Frame::WebTransportStream(SessionId::decode(buf)?)); @@ -107,7 +107,7 @@ impl Frame { let mut payload = buf.take(len as usize); - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!("frame ty: {:?}", ty); let frame = match ty { @@ -129,7 +129,7 @@ impl Frame { }; if let Ok(_frame) = &frame { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!( "got frame {:?}, len: {}, remaining: {}", _frame, @@ -543,7 +543,7 @@ impl Settings { //# H3_SETTINGS_ERROR. settings.insert(identifier, value)?; } else { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::debug!("Unsupported setting: {:#x?}", identifier); } } diff --git a/h3/src/qpack/decoder.rs b/h3/src/qpack/decoder.rs index 10bddb41..48c1bf7e 100644 --- a/h3/src/qpack/decoder.rs +++ b/h3/src/qpack/decoder.rs @@ -1,7 +1,7 @@ use bytes::{Buf, BufMut}; use std::{convert::TryInto, fmt, io::Cursor, num::TryFromIntError}; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::trace; use super::{ @@ -119,7 +119,7 @@ impl Decoder { let inserted_on_start = self.table.total_inserted(); while let Some(instruction) = self.parse_instruction(read)? { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!("instruction {:?}", instruction); match instruction { diff --git a/h3/src/server/connection.rs b/h3/src/server/connection.rs index 847d5dbe..cf7a0941 100644 --- a/h3/src/server/connection.rs +++ b/h3/src/server/connection.rs @@ -37,7 +37,7 @@ use crate::{ use crate::server::request::ResolveRequest; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::{instrument, trace, warn}; use super::stream::{ReadDatagram, RequestStream}; @@ -90,13 +90,13 @@ where /// Use a custom [`super::builder::Builder`] with [`super::builder::builder()`] to create a connection /// with different settings. /// Provide a Connection which implements [`quic::Connection`]. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn new(conn: C) -> Result { super::builder::builder().build(conn).await } /// Closes the connection with a code and a reason. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn close>(&mut self, code: Code, reason: T) -> Error { self.inner.close(code, reason) } @@ -112,7 +112,7 @@ where /// It returns a tuple with a [`http::Request`] and an [`RequestStream`]. /// The [`http::Request`] is the received request from the client. /// The [`RequestStream`] can be used to send the response. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn accept( &mut self, ) -> Result, RequestStream)>, Error> { @@ -158,7 +158,7 @@ where /// This is needed as a bidirectional stream may be read as part of incoming webtransport /// bi-streams. If it turns out that the stream is *not* a `WEBTRANSPORT_STREAM` the request /// may still want to be handled and passed to the user. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn accept_with_frame( &mut self, mut stream: FrameStream, @@ -290,7 +290,7 @@ where /// Initiate a graceful shutdown, accepting `max_request` potentially still in-flight /// /// See [connection shutdown](https://www.rfc-editor.org/rfc/rfc9114.html#connection-shutdown) for more information. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn shutdown(&mut self, max_requests: usize) -> Result<(), Error> { let max_id = self .last_accepted_stream @@ -304,7 +304,7 @@ where /// /// This could be either a *Request* or a *WebTransportBiStream*, the first frame's type /// decides. - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_accept_request( &mut self, cx: &mut Context<'_>, @@ -353,13 +353,13 @@ where } } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub(crate) fn poll_control(&mut self, cx: &mut Context<'_>) -> Poll> { while (self.poll_next_control(cx)?).is_ready() {} Poll::Pending } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub(crate) fn poll_next_control( &mut self, cx: &mut Context<'_>, @@ -368,13 +368,13 @@ where match &frame { Frame::Settings(_setting) => { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] trace!("Got settings > {:?}", _setting); () } &Frame::Goaway(id) => self.inner.process_goaway(&mut self.recv_closing, id)?, _frame @ Frame::MaxPushId(_) | _frame @ Frame::CancelPush(_) => { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] warn!("Control frame ignored {:?}", _frame); //= https://www.rfc-editor.org/rfc/rfc9114#section-7.2.3 @@ -405,7 +405,7 @@ where Poll::Ready(Ok(frame)) } - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] fn poll_requests_completion(&mut self, cx: &mut Context<'_>) -> Poll<()> { loop { match self.request_end_recv.poll_recv(cx) { @@ -435,13 +435,13 @@ where B: Buf, { /// Sends a datagram - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn send_datagram(&mut self, stream_id: StreamId, data: B) -> Result<(), Error> { self.inner .conn .send_datagram(Datagram::new(stream_id, data))?; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::info!("Sent datagram"); Ok(()) @@ -454,7 +454,7 @@ where B: Buf, { /// Reads an incoming datagram - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn read_datagram(&mut self) -> ReadDatagram { ReadDatagram { conn: self, @@ -468,7 +468,7 @@ where C: quic::Connection, B: Buf, { - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] fn drop(&mut self) { self.inner.close(Code::H3_NO_ERROR, ""); } diff --git a/h3/src/server/request.rs b/h3/src/server/request.rs index 79454e35..7d986c86 100644 --- a/h3/src/server/request.rs +++ b/h3/src/server/request.rs @@ -3,7 +3,7 @@ use std::convert::TryFrom; use bytes::Buf; use http::{Request, StatusCode}; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::instrument; use crate::{error::Code, proto::headers::Header, qpack, quic, Error}; @@ -31,7 +31,7 @@ impl> ResolveRequest { } /// Finishes the resolution of the request - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn resolve( mut self, ) -> Result<(Request<()>, RequestStream), Error> { @@ -93,7 +93,7 @@ impl> ResolveRequest { // send the grease frame only once // self.inner.send_grease_frame = false; - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::trace!("replying with: {:?}", req); Ok((req, self.request_stream)) diff --git a/h3/src/server/stream.rs b/h3/src/server/stream.rs index 3f333903..11a9d0cd 100644 --- a/h3/src/server/stream.rs +++ b/h3/src/server/stream.rs @@ -33,7 +33,7 @@ use crate::{ stream::{self}, }; -#[cfg(feature = "tracing")] +#[cfg(feature = "h3-tracing")] use tracing::{error, instrument}; /// Manage request and response transfer for an incoming request @@ -63,13 +63,13 @@ where B: Buf, { /// Receive data sent from the client - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_data(&mut self) -> Result, Error> { self.inner.recv_data().await } /// Poll for data sent from the client - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn poll_recv_data( &mut self, cx: &mut Context<'_>, @@ -78,13 +78,13 @@ where } /// Receive an optional set of trailers for the request - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub async fn recv_trailers(&mut self) -> Result, Error> { self.inner.recv_trailers().await } /// Tell the peer to stop sending into the underlying QUIC stream - #[cfg_attr(feature = "enable-tracing", instrument(skip_all))] + #[cfg_attr(feature = "h3-tracing", instrument(skip_all))] pub fn stop_sending(&mut self, error_code: crate::error::Code) { self.inner.stream.stop_sending(error_code) } @@ -211,7 +211,7 @@ where impl Drop for RequestEnd { fn drop(&mut self) { if let Err(_error) = self.request_end.send(self.stream_id) { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] error!( "failed to notify connection of request end: {} {}", self.stream_id, _error @@ -240,7 +240,7 @@ where type Output = Result>, Error>; fn poll(mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - #[cfg(feature = "tracing")] + #[cfg(feature = "h3-tracing")] tracing::trace!("poll: read_datagram"); match ready!(self.conn.inner.conn.poll_accept_datagram(cx))? { From f92891b048213cabad570e1391046f4218b2ae25 Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:55:00 +0200 Subject: [PATCH 09/10] examples --- examples/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 12af7760..9511344d 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -10,8 +10,8 @@ edition = "2021" anyhow = "1.0" bytes = "1" futures = "0.3" -h3 = { path = "../h3", features = ["enable-tracing"] } -h3-quinn = { path = "../h3-quinn", features = ["enable-tracing"] } +h3 = { path = "../h3", features = ["h3-tracing"] } +h3-quinn = { path = "../h3-quinn", features = ["h3-quinn-tracing"] } h3-webtransport = { path = "../h3-webtransport" } http = "1" quinn = { version = "0.11", default-features = false, features = [ From 17fc1eec48dec2da7750d25627276038dc4dbe9d Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 21 Jun 2024 22:57:11 +0200 Subject: [PATCH 10/10] CI --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a6e69174..7180c4ae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -111,7 +111,7 @@ jobs: matrix: os: [ubuntu-latest] toolchain: [stable, beta] - features: [i-implement-a-third-party-backend-and-opt-into-breaking-changes, enable-tracing, 'enable-tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes'] + features: [i-implement-a-third-party-backend-and-opt-into-breaking-changes, h3-tracing, 'h3-tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3