@@ -252,6 +252,10 @@ enum WakeOp {
252
252
Drop ,
253
253
}
254
254
255
+ /// Marker type used to indicate that a span is actually tracked by the console.
256
+ #[ derive( Debug ) ]
257
+ struct Tracked { }
258
+
255
259
impl ConsoleLayer {
256
260
/// Returns a `ConsoleLayer` built with the default settings.
257
261
///
@@ -377,10 +381,6 @@ impl ConsoleLayer {
377
381
self . async_op_callsites . contains ( meta)
378
382
}
379
383
380
- fn is_async_op_poll ( & self , meta : & ' static Metadata < ' static > ) -> bool {
381
- self . async_op_poll_callsites . contains ( meta)
382
- }
383
-
384
384
fn is_id_spawned < S > ( & self , id : & span:: Id , cx : & Context < ' _ , S > ) -> bool
385
385
where
386
386
S : Subscriber + for < ' a > LookupSpan < ' a > ,
@@ -408,25 +408,15 @@ impl ConsoleLayer {
408
408
. unwrap_or ( false )
409
409
}
410
410
411
- fn is_id_async_op_poll < S > ( & self , id : & span:: Id , cx : & Context < ' _ , S > ) -> bool
411
+ fn is_id_tracked < S > ( & self , id : & span:: Id , cx : & Context < ' _ , S > ) -> bool
412
412
where
413
413
S : Subscriber + for < ' a > LookupSpan < ' a > ,
414
414
{
415
415
cx. span ( id)
416
- . map ( |span| self . is_async_op_poll ( span . metadata ( ) ) )
416
+ . map ( |span| span . extensions ( ) . get :: < Tracked > ( ) . is_some ( ) )
417
417
. unwrap_or ( false )
418
418
}
419
419
420
- fn is_id_tracked < S > ( & self , id : & span:: Id , cx : & Context < ' _ , S > ) -> bool
421
- where
422
- S : Subscriber + for < ' a > LookupSpan < ' a > ,
423
- {
424
- self . is_id_async_op ( id, cx)
425
- || self . is_id_resource ( id, cx)
426
- || self . is_id_spawned ( id, cx)
427
- || self . is_id_async_op_poll ( id, cx)
428
- }
429
-
430
420
fn first_entered < P > ( & self , stack : & SpanStack , p : P ) -> Option < span:: Id >
431
421
where
432
422
P : Fn ( & span:: Id ) -> bool ,
@@ -440,28 +430,36 @@ impl ConsoleLayer {
440
430
. cloned ( )
441
431
}
442
432
443
- fn send ( & self , dropped : & AtomicUsize , event : Event ) {
433
+ fn send ( & self , dropped : & AtomicUsize , event : Event ) -> bool {
444
434
use mpsc:: error:: TrySendError ;
445
435
446
- match self . tx . try_reserve ( ) {
447
- Ok ( permit) => permit. send ( event) ,
436
+ // Return whether or not we actually sent the event.
437
+ let sent = match self . tx . try_reserve ( ) {
438
+ Ok ( permit) => {
439
+ permit. send ( event) ;
440
+ true
441
+ }
448
442
Err ( TrySendError :: Closed ( _) ) => {
449
443
// we should warn here eventually, but nop for now because we
450
444
// can't trigger tracing events...
445
+ false
451
446
}
452
447
Err ( TrySendError :: Full ( _) ) => {
453
448
// this shouldn't happen, since we trigger a flush when
454
449
// approaching the high water line...but if the executor wait
455
450
// time is very high, maybe the aggregator task hasn't been
456
451
// polled yet. so... eek?!
457
452
dropped. fetch_add ( 1 , Ordering :: Release ) ;
453
+ false
458
454
}
459
- }
455
+ } ;
460
456
461
457
let capacity = self . tx . capacity ( ) ;
462
458
if capacity <= self . flush_under_capacity {
463
459
self . shared . flush . trigger ( ) ;
464
460
}
461
+
462
+ sent
465
463
}
466
464
}
467
465
@@ -512,7 +510,7 @@ where
512
510
513
511
fn on_new_span ( & self , attrs : & span:: Attributes < ' _ > , id : & span:: Id , ctx : Context < ' _ , S > ) {
514
512
let metadata = attrs. metadata ( ) ;
515
- if self . is_spawn ( metadata) {
513
+ let sent = if self . is_spawn ( metadata) {
516
514
let at = SystemTime :: now ( ) ;
517
515
let mut task_visitor = TaskVisitor :: new ( metadata. into ( ) ) ;
518
516
attrs. record ( & mut task_visitor) ;
@@ -526,11 +524,8 @@ where
526
524
fields,
527
525
location,
528
526
} ,
529
- ) ;
530
- return ;
531
- }
532
-
533
- if self . is_resource ( metadata) {
527
+ )
528
+ } else if self . is_resource ( metadata) {
534
529
let mut resource_visitor = ResourceVisitor :: default ( ) ;
535
530
attrs. record ( & mut resource_visitor) ;
536
531
if let Some ( result) = resource_visitor. result ( ) {
@@ -558,12 +553,12 @@ where
558
553
is_internal,
559
554
inherit_child_attrs,
560
555
} ,
561
- ) ;
562
- } // else unknown resource span format
563
- return ;
564
- }
565
-
566
- if self . is_async_op ( metadata) {
556
+ )
557
+ } else {
558
+ // else unknown resource span format
559
+ false
560
+ }
561
+ } else if self . is_async_op ( metadata) {
567
562
let mut async_op_visitor = AsyncOpVisitor :: default ( ) ;
568
563
attrs. record ( & mut async_op_visitor) ;
569
564
if let Some ( ( source, inherit_child_attrs) ) = async_op_visitor. result ( ) {
@@ -588,10 +583,30 @@ where
588
583
source,
589
584
inherit_child_attrs,
590
585
} ,
591
- ) ;
586
+ )
587
+ } else {
588
+ false
592
589
}
590
+ } else {
591
+ // else async op span needs to have a source field
592
+ false
593
+ }
594
+ } else {
595
+ false
596
+ } ;
597
+
598
+ // If we were able to record the span, add a marker extension indicating
599
+ // that it's tracked by the console.
600
+ if sent {
601
+ if let Some ( span) = ctx. span ( id) {
602
+ span. extensions_mut ( ) . insert ( Tracked { } ) ;
603
+ } else {
604
+ debug_assert ! (
605
+ false ,
606
+ "span should exist if `on_new_span` was called for its ID ({:?})" ,
607
+ id
608
+ ) ;
593
609
}
594
- // else async op span needs to have a source field
595
610
}
596
611
}
597
612
@@ -673,7 +688,7 @@ where
673
688
update_type : UpdateType :: Resource ,
674
689
update,
675
690
} ,
676
- )
691
+ ) ;
677
692
}
678
693
}
679
694
return ;
0 commit comments