Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up to tracing #248

Merged
merged 5 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
matrix:
os: [ubuntu-latest]
toolchain: [stable, beta]
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']
features: [i-implement-a-third-party-backend-and-opt-into-breaking-changes, tracing, 'tracing,i-implement-a-third-party-backend-and-opt-into-breaking-changes']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ edition = "2021"
anyhow = "1.0"
bytes = "1"
futures = "0.3"
h3 = { path = "../h3", features = ["h3-tracing"] }
h3-quinn = { path = "../h3-quinn", features = ["h3-quinn-tracing"] }
h3 = { path = "../h3", features = ["tracing"] }
h3-quinn = { path = "../h3-quinn", features = ["tracing"] }
h3-webtransport = { path = "../h3-webtransport" }
http = "1"
quinn = { version = "0.11", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion h3-quinn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ tokio = { version = "1", features = ["io-util"], default-features = false }
tracing = { version = "0.1.40", optional = true }

[features]
h3-quinn-tracing = ["tracing"]
tracing = ["dep:tracing"]
40 changes: 20 additions & 20 deletions h3-quinn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use h3::{
};
use tokio_util::sync::ReusableBoxFuture;

#[cfg(feature = "h3-quinn-tracing")]
#[cfg(feature = "tracing")]
use tracing::instrument;

/// A QUIC connection backed by Quinn
Expand Down Expand Up @@ -158,7 +158,7 @@ where
type OpenStreams = OpenStreams;
type AcceptError = ConnectionError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_accept_bidi(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -173,7 +173,7 @@ where
})))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_accept_recv(
&mut self,
cx: &mut task::Context<'_>,
Expand Down Expand Up @@ -202,7 +202,7 @@ where
type BidiStream = BidiStream<B>;
type OpenError = ConnectionError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_open_bidi(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -221,7 +221,7 @@ where
}))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_open_send(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -236,7 +236,7 @@ where
Poll::Ready(Ok(Self::SendStream::new(send)))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
self.conn.close(
VarInt::from_u64(code.value()).expect("error code VarInt"),
Expand All @@ -251,7 +251,7 @@ where
{
type Error = SendDatagramError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn send_datagram(&mut self, data: Datagram<B>) -> Result<(), SendDatagramError> {
// TODO investigate static buffer from known max datagram size
let mut buf = BytesMut::new();
Expand All @@ -268,7 +268,7 @@ impl quic::RecvDatagramExt for Connection {
type Error = ConnectionError;

#[inline]
#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_accept_datagram(
&mut self,
cx: &mut task::Context<'_>,
Expand Down Expand Up @@ -299,7 +299,7 @@ where
type BidiStream = BidiStream<B>;
type OpenError = ConnectionError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_open_bidi(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -318,7 +318,7 @@ where
}))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_open_send(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -333,7 +333,7 @@ where
Poll::Ready(Ok(Self::SendStream::new(send)))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
self.conn.close(
VarInt::from_u64(code.value()).expect("error code VarInt"),
Expand Down Expand Up @@ -465,7 +465,7 @@ impl quic::RecvStream for RecvStream {
type Buf = Bytes;
type Error = ReadError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_data(
&mut self,
cx: &mut task::Context<'_>,
Expand All @@ -482,7 +482,7 @@ impl quic::RecvStream for RecvStream {
Poll::Ready(Ok(chunk?.map(|c| c.bytes)))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn stop_sending(&mut self, error_code: u64) {
self.stream
.as_mut()
Expand All @@ -491,7 +491,7 @@ impl quic::RecvStream for RecvStream {
.ok();
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn recv_id(&self) -> StreamId {
self.stream
.as_ref()
Expand Down Expand Up @@ -589,7 +589,7 @@ where
{
type Error = SendStreamError;

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
if let Some(ref mut data) = self.writing {
while data.has_remaining() {
Expand All @@ -615,12 +615,12 @@ where
Poll::Ready(Ok(()))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_finish(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(self.stream.as_mut().unwrap().finish().map_err(|e| e.into()))
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn reset(&mut self, reset_code: u64) {
let _ = self
.stream
Expand All @@ -629,7 +629,7 @@ where
.reset(VarInt::from_u64(reset_code).unwrap_or(VarInt::MAX));
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn send_data<D: Into<WriteBuf<B>>>(&mut self, data: D) -> Result<(), Self::Error> {
if self.writing.is_some() {
return Err(Self::Error::NotReady);
Expand All @@ -638,7 +638,7 @@ where
Ok(())
}

#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn send_id(&self) -> StreamId {
self.stream
.as_ref()
Expand All @@ -654,7 +654,7 @@ impl<B> quic::SendStreamUnframed<B> for SendStream<B>
where
B: Buf,
{
#[cfg_attr(feature = "h3-quinn-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
fn poll_send<D: Buf>(
&mut self,
cx: &mut task::Context<'_>,
Expand Down
2 changes: 1 addition & 1 deletion h3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ categories = [

[features]
i-implement-a-third-party-backend-and-opt-into-breaking-changes = []
h3-tracing = ["tracing"]
tracing = ["dep:tracing"]

[dependencies]
bytes = "1"
Expand Down
14 changes: 7 additions & 7 deletions h3/src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use futures_util::future;
use http::request;

#[cfg(feature = "h3-tracing")]
#[cfg(feature = "tracing")]
use tracing::{info, instrument, trace};

use crate::{
Expand Down Expand Up @@ -123,7 +123,7 @@
B: Buf,
{
/// Send an HTTP/3 request to the server
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn send_request(
&mut self,
req: http::Request<()>,
Expand Down Expand Up @@ -349,20 +349,20 @@
B: Buf,
{
/// Initiate a graceful shutdown, accepting `max_push` potentially in-flight server pushes
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
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 = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
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 = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
while let Poll::Ready(result) = self.inner.poll_control(cx) {
match result {
Expand All @@ -386,9 +386,9 @@
//# Once a server has provided new settings,
//# clients MUST comply with those values.
Ok(Frame::Settings(_)) => {
#[cfg(feature = "h3-tracing")]
#[cfg(feature = "tracing")]
trace!("Got settings");
()

Check warning on line 391 in h3/src/client/connection.rs

View workflow job for this annotation

GitHub Actions / Lint

unneeded unit expression
}

Ok(Frame::Goaway(id)) => {
Expand All @@ -406,7 +406,7 @@
}
self.inner.process_goaway(&mut self.recv_closing, id)?;

#[cfg(feature = "h3-tracing")]
#[cfg(feature = "tracing")]
info!("Server initiated graceful shutdown, last: StreamId({})", id);
}

Expand Down
16 changes: 8 additions & 8 deletions h3/src/client/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bytes::Buf;
use futures_util::future;
use http::{HeaderMap, Response};
#[cfg(feature = "h3-tracing")]
#[cfg(feature = "tracing")]
use tracing::instrument;

use crate::{
Expand Down Expand Up @@ -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 = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn recv_response(&mut self) -> Result<Response<()>, Error> {
let mut frame = future::poll_fn(|cx| self.inner.stream.poll_next(cx))
.await
Expand Down Expand Up @@ -144,13 +144,13 @@ where

/// Receive some of the request body.
// TODO what if called before recv_response ?
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
self.inner.recv_data().await
}

/// Receive an optional set of trailers for the response.
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn recv_trailers(&mut self) -> Result<Option<HeaderMap>, Error> {
let res = self.inner.recv_trailers().await;
if let Err(ref e) = res {
Expand All @@ -162,7 +162,7 @@ where
}

/// Tell the peer to stop sending into the underlying QUIC stream
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
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()` ?
Expand All @@ -176,7 +176,7 @@ where
B: Buf,
{
/// Send some data on the request body.
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn send_data(&mut self, buf: B) -> Result<(), Error> {
self.inner.send_data(buf).await
}
Expand All @@ -186,7 +186,7 @@ where
/// Either [`RequestStream::finish`] or
/// [`RequestStream::send_trailers`] must be called to finalize a
/// request.
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> {
self.inner.send_trailers(trailers).await
}
Expand All @@ -196,7 +196,7 @@ where
/// Either [`RequestStream::finish`] or
/// [`RequestStream::send_trailers`] must be called to finalize a
/// request.
#[cfg_attr(feature = "h3-tracing", instrument(skip_all))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub async fn finish(&mut self) -> Result<(), Error> {
self.inner.finish().await
}
Expand Down
2 changes: 1 addition & 1 deletion h3/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TryFrom<Config> for frame::Settings {
match settings.insert(frame::SettingId::grease(), 0) {
Ok(_) => (),
Err(_err) => {
#[cfg(feature = "h3-tracing")]
#[cfg(feature = "tracing")]
tracing::warn!("Error when adding the grease Setting. Reason {}", _err);
}
}
Expand Down
Loading
Loading