4444 /// Stream state handler
4545 streams : Streams < B , P > ,
4646
47+ /// A `tracing` span tracking the lifetime of the connection.
48+ span : tracing:: Span ,
49+
4750 /// Client or server
4851 _phantom : PhantomData < P > ,
4952}
@@ -100,6 +103,7 @@ where
100103 ping_pong : PingPong :: new ( ) ,
101104 settings : Settings :: new ( config. settings ) ,
102105 streams,
106+ span : tracing:: debug_span!( "Connection" , peer = %P :: NAME ) ,
103107 _phantom : PhantomData ,
104108 }
105109 }
@@ -121,6 +125,9 @@ where
121125 /// Returns `RecvError` as this may raise errors that are caused by delayed
122126 /// processing of received frames.
123127 fn poll_ready ( & mut self , cx : & mut Context ) -> Poll < Result < ( ) , RecvError > > {
128+ let _e = self . span . enter ( ) ;
129+ let span = tracing:: trace_span!( "poll_ready" ) ;
130+ let _e = span. enter ( ) ;
124131 // The order of these calls don't really matter too much
125132 ready ! ( self . ping_pong. send_pending_pong( cx, & mut self . codec) ) ?;
126133 ready ! ( self . ping_pong. send_pending_ping( cx, & mut self . codec) ) ?;
@@ -200,9 +207,18 @@ where
200207
201208 /// Advances the internal state of the connection.
202209 pub fn poll ( & mut self , cx : & mut Context ) -> Poll < Result < ( ) , proto:: Error > > {
210+ // XXX(eliza): cloning the span is unfortunately necessary here in
211+ // order to placate the borrow checker — `self` is mutably borrowed by
212+ // `poll2`, which means that we can't borrow `self.span` to enter it.
213+ // The clone is just an atomic ref bump.
214+ let span = self . span . clone ( ) ;
215+ let _e = span. enter ( ) ;
216+ let span = tracing:: trace_span!( "poll" ) ;
217+ let _e = span. enter ( ) ;
203218 use crate :: codec:: RecvError :: * ;
204219
205220 loop {
221+ tracing:: trace!( connection. state = ?self . state) ;
206222 // TODO: probably clean up this glob of code
207223 match self . state {
208224 // When open, continue to poll a frame
@@ -230,7 +246,7 @@ where
230246 // error. This is handled by setting a GOAWAY frame followed by
231247 // terminating the connection.
232248 Poll :: Ready ( Err ( Connection ( e) ) ) => {
233- tracing:: debug!( "Connection::poll; connection error={:?}" , e ) ;
249+ tracing:: debug!( error = ?e , "Connection::poll; connection error" ) ;
234250
235251 // We may have already sent a GOAWAY for this error,
236252 // if so, don't send another, just flush and close up.
@@ -250,15 +266,15 @@ where
250266 // This is handled by resetting the frame then trying to read
251267 // another frame.
252268 Poll :: Ready ( Err ( Stream { id, reason } ) ) => {
253- tracing:: trace!( "stream error; id={:?}; reason={:?}" , id , reason ) ;
269+ tracing:: trace!( ?id , ?reason , "stream error" ) ;
254270 self . streams . send_reset ( id, reason) ;
255271 }
256272 // Attempting to read a frame resulted in an I/O error. All
257273 // active streams must be reset.
258274 //
259275 // TODO: Are I/O errors recoverable?
260276 Poll :: Ready ( Err ( Io ( e) ) ) => {
261- tracing:: debug!( "Connection::poll; IO error={:?}" , e ) ;
277+ tracing:: debug!( error = ?e , "Connection::poll; IO error" ) ;
262278 let e = e. into ( ) ;
263279
264280 // Reset all active streams
@@ -317,28 +333,28 @@ where
317333
318334 match ready ! ( Pin :: new( & mut self . codec) . poll_next( cx) ?) {
319335 Some ( Headers ( frame) ) => {
320- tracing:: trace!( "recv HEADERS; frame={:?}" , frame ) ;
336+ tracing:: trace!( ?frame , "recv HEADERS" ) ;
321337 self . streams . recv_headers ( frame) ?;
322338 }
323339 Some ( Data ( frame) ) => {
324- tracing:: trace!( "recv DATA; frame={:?}" , frame ) ;
340+ tracing:: trace!( ?frame , "recv DATA" ) ;
325341 self . streams . recv_data ( frame) ?;
326342 }
327343 Some ( Reset ( frame) ) => {
328- tracing:: trace!( "recv RST_STREAM; frame={:?}" , frame ) ;
344+ tracing:: trace!( ?frame , "recv RST_STREAM" ) ;
329345 self . streams . recv_reset ( frame) ?;
330346 }
331347 Some ( PushPromise ( frame) ) => {
332- tracing:: trace!( "recv PUSH_PROMISE; frame={:?}" , frame ) ;
348+ tracing:: trace!( ?frame , "recv PUSH_PROMISE" ) ;
333349 self . streams . recv_push_promise ( frame) ?;
334350 }
335351 Some ( Settings ( frame) ) => {
336- tracing:: trace!( "recv SETTINGS; frame={:?}" , frame ) ;
352+ tracing:: trace!( ?frame , "recv SETTINGS" ) ;
337353 self . settings
338354 . recv_settings ( frame, & mut self . codec , & mut self . streams ) ?;
339355 }
340356 Some ( GoAway ( frame) ) => {
341- tracing:: trace!( "recv GOAWAY; frame={:?}" , frame ) ;
357+ tracing:: trace!( ?frame , "recv GOAWAY" ) ;
342358 // This should prevent starting new streams,
343359 // but should allow continuing to process current streams
344360 // until they are all EOS. Once they are, State should
@@ -347,7 +363,7 @@ where
347363 self . error = Some ( frame. reason ( ) ) ;
348364 }
349365 Some ( Ping ( frame) ) => {
350- tracing:: trace!( "recv PING; frame={:?}" , frame ) ;
366+ tracing:: trace!( ?frame , "recv PING" ) ;
351367 let status = self . ping_pong . recv_ping ( frame) ;
352368 if status. is_shutdown ( ) {
353369 assert ! (
@@ -360,11 +376,11 @@ where
360376 }
361377 }
362378 Some ( WindowUpdate ( frame) ) => {
363- tracing:: trace!( "recv WINDOW_UPDATE; frame={:?}" , frame ) ;
379+ tracing:: trace!( ?frame , "recv WINDOW_UPDATE" ) ;
364380 self . streams . recv_window_update ( frame) ?;
365381 }
366382 Some ( Priority ( frame) ) => {
367- tracing:: trace!( "recv PRIORITY; frame={:?}" , frame ) ;
383+ tracing:: trace!( ?frame , "recv PRIORITY" ) ;
368384 // TODO: handle
369385 }
370386 None => {
0 commit comments