Skip to content

Commit 98db57d

Browse files
committed
add tracing instrumentation
1 parent 983c853 commit 98db57d

File tree

8 files changed

+75
-5
lines changed

8 files changed

+75
-5
lines changed

h3-quinn/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ quinn = { version = "0.11", default-features = false, features = [
2121
tokio-util = { version = "0.7.9" }
2222
futures = { version = "0.3.28" }
2323
tokio = { version = "1", features = ["io-util"], default-features = false }
24+
tracing = "0.1.40"

h3-quinn/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use h3::{
2727
quic::{self, Error, StreamId, WriteBuf},
2828
};
2929
use tokio_util::sync::ReusableBoxFuture;
30+
use tracing::instrument;
3031

3132
/// A QUIC connection backed by Quinn
3233
///
@@ -155,6 +156,7 @@ where
155156
type OpenStreams = OpenStreams;
156157
type AcceptError = ConnectionError;
157158

159+
#[instrument(skip_all)]
158160
fn poll_accept_bidi(
159161
&mut self,
160162
cx: &mut task::Context<'_>,
@@ -169,6 +171,7 @@ where
169171
})))
170172
}
171173

174+
#[instrument(skip_all)]
172175
fn poll_accept_recv(
173176
&mut self,
174177
cx: &mut task::Context<'_>,
@@ -197,6 +200,7 @@ where
197200
type BidiStream = BidiStream<B>;
198201
type OpenError = ConnectionError;
199202

203+
#[instrument(skip_all)]
200204
fn poll_open_bidi(
201205
&mut self,
202206
cx: &mut task::Context<'_>,
@@ -215,6 +219,7 @@ where
215219
}))
216220
}
217221

222+
#[instrument(skip_all)]
218223
fn poll_open_send(
219224
&mut self,
220225
cx: &mut task::Context<'_>,
@@ -229,6 +234,7 @@ where
229234
Poll::Ready(Ok(Self::SendStream::new(send)))
230235
}
231236

237+
#[instrument(skip_all)]
232238
fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
233239
self.conn.close(
234240
VarInt::from_u64(code.value()).expect("error code VarInt"),
@@ -243,6 +249,7 @@ where
243249
{
244250
type Error = SendDatagramError;
245251

252+
#[instrument(skip_all)]
246253
fn send_datagram(&mut self, data: Datagram<B>) -> Result<(), SendDatagramError> {
247254
// TODO investigate static buffer from known max datagram size
248255
let mut buf = BytesMut::new();
@@ -259,6 +266,7 @@ impl quic::RecvDatagramExt for Connection {
259266
type Error = ConnectionError;
260267

261268
#[inline]
269+
#[instrument(skip_all)]
262270
fn poll_accept_datagram(
263271
&mut self,
264272
cx: &mut task::Context<'_>,
@@ -289,6 +297,7 @@ where
289297
type BidiStream = BidiStream<B>;
290298
type OpenError = ConnectionError;
291299

300+
#[instrument(skip_all)]
292301
fn poll_open_bidi(
293302
&mut self,
294303
cx: &mut task::Context<'_>,
@@ -307,6 +316,7 @@ where
307316
}))
308317
}
309318

319+
#[instrument(skip_all)]
310320
fn poll_open_send(
311321
&mut self,
312322
cx: &mut task::Context<'_>,
@@ -321,6 +331,7 @@ where
321331
Poll::Ready(Ok(Self::SendStream::new(send)))
322332
}
323333

334+
#[instrument(skip_all)]
324335
fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
325336
self.conn.close(
326337
VarInt::from_u64(code.value()).expect("error code VarInt"),
@@ -452,6 +463,7 @@ impl quic::RecvStream for RecvStream {
452463
type Buf = Bytes;
453464
type Error = ReadError;
454465

466+
#[instrument(skip_all)]
455467
fn poll_data(
456468
&mut self,
457469
cx: &mut task::Context<'_>,
@@ -468,6 +480,7 @@ impl quic::RecvStream for RecvStream {
468480
Poll::Ready(Ok(chunk?.map(|c| c.bytes)))
469481
}
470482

483+
#[instrument(skip_all)]
471484
fn stop_sending(&mut self, error_code: u64) {
472485
self.stream
473486
.as_mut()
@@ -476,6 +489,7 @@ impl quic::RecvStream for RecvStream {
476489
.ok();
477490
}
478491

492+
#[instrument(skip_all)]
479493
fn recv_id(&self) -> StreamId {
480494
self.stream
481495
.as_ref()
@@ -573,6 +587,7 @@ where
573587
{
574588
type Error = SendStreamError;
575589

590+
#[instrument(skip_all)]
576591
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
577592
if let Some(ref mut data) = self.writing {
578593
while data.has_remaining() {
@@ -598,10 +613,12 @@ where
598613
Poll::Ready(Ok(()))
599614
}
600615

616+
#[instrument(skip_all)]
601617
fn poll_finish(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
602618
Poll::Ready(self.stream.as_mut().unwrap().finish().map_err(|e| e.into()))
603619
}
604620

621+
#[instrument(skip_all)]
605622
fn reset(&mut self, reset_code: u64) {
606623
let _ = self
607624
.stream
@@ -610,6 +627,7 @@ where
610627
.reset(VarInt::from_u64(reset_code).unwrap_or(VarInt::MAX));
611628
}
612629

630+
#[instrument(skip_all)]
613631
fn send_data<D: Into<WriteBuf<B>>>(&mut self, data: D) -> Result<(), Self::Error> {
614632
if self.writing.is_some() {
615633
return Err(Self::Error::NotReady);
@@ -618,6 +636,7 @@ where
618636
Ok(())
619637
}
620638

639+
#[instrument(skip_all)]
621640
fn send_id(&self) -> StreamId {
622641
self.stream
623642
.as_ref()
@@ -633,6 +652,7 @@ impl<B> quic::SendStreamUnframed<B> for SendStream<B>
633652
where
634653
B: Buf,
635654
{
655+
#[instrument(skip_all)]
636656
fn poll_send<D: Buf>(
637657
&mut self,
638658
cx: &mut task::Context<'_>,

h3/src/client/connection.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use bytes::{Buf, BytesMut};
1010
use futures_util::future;
1111
use http::request;
12-
use tracing::{info, trace};
12+
use tracing::{info, instrument, trace};
1313

1414
use crate::{
1515
connection::{self, ConnectionInner, ConnectionState, SharedStateRef},
@@ -121,6 +121,7 @@ where
121121
B: Buf,
122122
{
123123
/// Send an HTTP/3 request to the server
124+
#[instrument(skip_all)]
124125
pub async fn send_request(
125126
&mut self,
126127
req: http::Request<()>,
@@ -346,17 +347,20 @@ where
346347
B: Buf,
347348
{
348349
/// Initiate a graceful shutdown, accepting `max_push` potentially in-flight server pushes
350+
#[instrument(skip_all)]
349351
pub async fn shutdown(&mut self, _max_push: usize) -> Result<(), Error> {
350352
// TODO: Calculate remaining pushes once server push is implemented.
351353
self.inner.shutdown(&mut self.sent_closing, PushId(0)).await
352354
}
353355

354356
/// Wait until the connection is closed
357+
#[instrument(skip_all)]
355358
pub async fn wait_idle(&mut self) -> Result<(), Error> {
356359
future::poll_fn(|cx| self.poll_close(cx)).await
357360
}
358361

359362
/// Maintain the connection state until it is closed
363+
#[instrument(skip_all)]
360364
pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
361365
while let Poll::Ready(result) = self.inner.poll_control(cx) {
362366
match result {

h3/src/client/stream.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bytes::Buf;
22
use futures_util::future;
33
use http::{HeaderMap, Response};
4+
use tracing::instrument;
45

56
use crate::{
67
connection::{self, ConnectionState, SharedStateRef},
@@ -82,6 +83,7 @@ where
8283
/// This should be called before trying to receive any data with [`recv_data()`].
8384
///
8485
/// [`recv_data()`]: #method.recv_data
86+
#[instrument(skip_all)]
8587
pub async fn recv_response(&mut self) -> Result<Response<()>, Error> {
8688
let mut frame = future::poll_fn(|cx| self.inner.stream.poll_next(cx))
8789
.await
@@ -141,11 +143,13 @@ where
141143

142144
/// Receive some of the request body.
143145
// TODO what if called before recv_response ?
146+
#[instrument(skip_all)]
144147
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
145148
self.inner.recv_data().await
146149
}
147150

148151
/// Receive an optional set of trailers for the response.
152+
#[instrument(skip_all)]
149153
pub async fn recv_trailers(&mut self) -> Result<Option<HeaderMap>, Error> {
150154
let res = self.inner.recv_trailers().await;
151155
if let Err(ref e) = res {
@@ -157,6 +161,7 @@ where
157161
}
158162

159163
/// Tell the peer to stop sending into the underlying QUIC stream
164+
#[instrument(skip_all)]
160165
pub fn stop_sending(&mut self, error_code: crate::error::Code) {
161166
// TODO take by value to prevent any further call as this request is cancelled
162167
// rename `cancel()` ?
@@ -170,6 +175,7 @@ where
170175
B: Buf,
171176
{
172177
/// Send some data on the request body.
178+
#[instrument(skip_all)]
173179
pub async fn send_data(&mut self, buf: B) -> Result<(), Error> {
174180
self.inner.send_data(buf).await
175181
}
@@ -179,6 +185,7 @@ where
179185
/// Either [`RequestStream::finish`] or
180186
/// [`RequestStream::send_trailers`] must be called to finalize a
181187
/// request.
188+
#[instrument(skip_all)]
182189
pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> {
183190
self.inner.send_trailers(trailers).await
184191
}
@@ -188,6 +195,7 @@ where
188195
/// Either [`RequestStream::finish`] or
189196
/// [`RequestStream::send_trailers`] must be called to finalize a
190197
/// request.
198+
#[instrument(skip_all)]
191199
pub async fn finish(&mut self) -> Result<(), Error> {
192200
self.inner.finish().await
193201
}

0 commit comments

Comments
 (0)