44
44
/// Stream state handler
45
45
streams : Streams < B , P > ,
46
46
47
+ /// A `tracing` span tracking the lifetime of the connection.
48
+ span : tracing:: Span ,
49
+
47
50
/// Client or server
48
51
_phantom : PhantomData < P > ,
49
52
}
@@ -100,6 +103,7 @@ where
100
103
ping_pong : PingPong :: new ( ) ,
101
104
settings : Settings :: new ( config. settings ) ,
102
105
streams,
106
+ span : tracing:: debug_span!( "Connection" , peer = %P :: NAME ) ,
103
107
_phantom : PhantomData ,
104
108
}
105
109
}
@@ -121,6 +125,9 @@ where
121
125
/// Returns `RecvError` as this may raise errors that are caused by delayed
122
126
/// processing of received frames.
123
127
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 ( ) ;
124
131
// The order of these calls don't really matter too much
125
132
ready ! ( self . ping_pong. send_pending_pong( cx, & mut self . codec) ) ?;
126
133
ready ! ( self . ping_pong. send_pending_ping( cx, & mut self . codec) ) ?;
@@ -200,9 +207,18 @@ where
200
207
201
208
/// Advances the internal state of the connection.
202
209
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 ( ) ;
203
218
use crate :: codec:: RecvError :: * ;
204
219
205
220
loop {
221
+ tracing:: trace!( connection. state = ?self . state) ;
206
222
// TODO: probably clean up this glob of code
207
223
match self . state {
208
224
// When open, continue to poll a frame
@@ -230,7 +246,7 @@ where
230
246
// error. This is handled by setting a GOAWAY frame followed by
231
247
// terminating the connection.
232
248
Poll :: Ready ( Err ( Connection ( e) ) ) => {
233
- tracing:: debug!( "Connection::poll; connection error={:?}" , e ) ;
249
+ tracing:: debug!( error = ?e , "Connection::poll; connection error" ) ;
234
250
235
251
// We may have already sent a GOAWAY for this error,
236
252
// if so, don't send another, just flush and close up.
@@ -250,15 +266,15 @@ where
250
266
// This is handled by resetting the frame then trying to read
251
267
// another frame.
252
268
Poll :: Ready ( Err ( Stream { id, reason } ) ) => {
253
- tracing:: trace!( "stream error; id={:?}; reason={:?}" , id , reason ) ;
269
+ tracing:: trace!( ?id , ?reason , "stream error" ) ;
254
270
self . streams . send_reset ( id, reason) ;
255
271
}
256
272
// Attempting to read a frame resulted in an I/O error. All
257
273
// active streams must be reset.
258
274
//
259
275
// TODO: Are I/O errors recoverable?
260
276
Poll :: Ready ( Err ( Io ( e) ) ) => {
261
- tracing:: debug!( "Connection::poll; IO error={:?}" , e ) ;
277
+ tracing:: debug!( error = ?e , "Connection::poll; IO error" ) ;
262
278
let e = e. into ( ) ;
263
279
264
280
// Reset all active streams
@@ -317,28 +333,28 @@ where
317
333
318
334
match ready ! ( Pin :: new( & mut self . codec) . poll_next( cx) ?) {
319
335
Some ( Headers ( frame) ) => {
320
- tracing:: trace!( "recv HEADERS; frame={:?}" , frame ) ;
336
+ tracing:: trace!( ?frame , "recv HEADERS" ) ;
321
337
self . streams . recv_headers ( frame) ?;
322
338
}
323
339
Some ( Data ( frame) ) => {
324
- tracing:: trace!( "recv DATA; frame={:?}" , frame ) ;
340
+ tracing:: trace!( ?frame , "recv DATA" ) ;
325
341
self . streams . recv_data ( frame) ?;
326
342
}
327
343
Some ( Reset ( frame) ) => {
328
- tracing:: trace!( "recv RST_STREAM; frame={:?}" , frame ) ;
344
+ tracing:: trace!( ?frame , "recv RST_STREAM" ) ;
329
345
self . streams . recv_reset ( frame) ?;
330
346
}
331
347
Some ( PushPromise ( frame) ) => {
332
- tracing:: trace!( "recv PUSH_PROMISE; frame={:?}" , frame ) ;
348
+ tracing:: trace!( ?frame , "recv PUSH_PROMISE" ) ;
333
349
self . streams . recv_push_promise ( frame) ?;
334
350
}
335
351
Some ( Settings ( frame) ) => {
336
- tracing:: trace!( "recv SETTINGS; frame={:?}" , frame ) ;
352
+ tracing:: trace!( ?frame , "recv SETTINGS" ) ;
337
353
self . settings
338
354
. recv_settings ( frame, & mut self . codec , & mut self . streams ) ?;
339
355
}
340
356
Some ( GoAway ( frame) ) => {
341
- tracing:: trace!( "recv GOAWAY; frame={:?}" , frame ) ;
357
+ tracing:: trace!( ?frame , "recv GOAWAY" ) ;
342
358
// This should prevent starting new streams,
343
359
// but should allow continuing to process current streams
344
360
// until they are all EOS. Once they are, State should
@@ -347,7 +363,7 @@ where
347
363
self . error = Some ( frame. reason ( ) ) ;
348
364
}
349
365
Some ( Ping ( frame) ) => {
350
- tracing:: trace!( "recv PING; frame={:?}" , frame ) ;
366
+ tracing:: trace!( ?frame , "recv PING" ) ;
351
367
let status = self . ping_pong . recv_ping ( frame) ;
352
368
if status. is_shutdown ( ) {
353
369
assert ! (
@@ -360,11 +376,11 @@ where
360
376
}
361
377
}
362
378
Some ( WindowUpdate ( frame) ) => {
363
- tracing:: trace!( "recv WINDOW_UPDATE; frame={:?}" , frame ) ;
379
+ tracing:: trace!( ?frame , "recv WINDOW_UPDATE" ) ;
364
380
self . streams . recv_window_update ( frame) ?;
365
381
}
366
382
Some ( Priority ( frame) ) => {
367
- tracing:: trace!( "recv PRIORITY; frame={:?}" , frame ) ;
383
+ tracing:: trace!( ?frame , "recv PRIORITY" ) ;
368
384
// TODO: handle
369
385
}
370
386
None => {
0 commit comments