@@ -25,7 +25,7 @@ use tracing_core::{
25
25
} ;
26
26
use tracing_subscriber:: {
27
27
layer:: Context ,
28
- registry:: { Extensions , LookupSpan , SpanRef } ,
28
+ registry:: { Extensions , LookupSpan } ,
29
29
Layer ,
30
30
} ;
31
31
@@ -789,87 +789,59 @@ where
789
789
}
790
790
791
791
fn on_enter ( & self , id : & span:: Id , cx : Context < ' _ , S > ) {
792
- fn update < S : Subscriber + for < ' a > LookupSpan < ' a > > (
793
- span : & SpanRef < S > ,
794
- at : Option < Instant > ,
795
- ) -> Option < Instant > {
792
+ if let Some ( span) = cx. span ( id) {
793
+ let now = Instant :: now ( ) ;
796
794
let exts = span. extensions ( ) ;
797
795
// if the span we are entering is a task or async op, record the
798
796
// poll stats.
799
797
if let Some ( stats) = exts. get :: < Arc < stats:: TaskStats > > ( ) {
800
- let at = at. unwrap_or_else ( Instant :: now) ;
801
- stats. start_poll ( at) ;
802
- Some ( at)
798
+ stats. start_poll ( now) ;
803
799
} else if let Some ( stats) = exts. get :: < Arc < stats:: AsyncOpStats > > ( ) {
804
- let at = at. unwrap_or_else ( Instant :: now) ;
805
- stats. start_poll ( at) ;
806
- Some ( at)
807
- // otherwise, is the span a resource? in that case, we also want
808
- // to enter it, although we don't care about recording poll
809
- // stats.
800
+ stats. start_poll ( now) ;
810
801
} else if exts. get :: < Arc < stats:: ResourceStats > > ( ) . is_some ( ) {
811
- Some ( at. unwrap_or_else ( Instant :: now) )
802
+ // otherwise, is the span a resource? in that case, we also want
803
+ // to enter it, although we don't care about recording poll
804
+ // stats.
812
805
} else {
813
- None
814
- }
815
- }
806
+ return ;
807
+ } ;
816
808
817
- if let Some ( span) = cx. span ( id) {
818
- if let Some ( now) = update ( & span, None ) {
819
- if let Some ( parent) = span. parent ( ) {
820
- update ( & parent, Some ( now) ) ;
821
- }
822
- self . current_spans
823
- . get_or_default ( )
824
- . borrow_mut ( )
825
- . push ( id. clone ( ) ) ;
826
-
827
- self . record ( || record:: Event :: Enter {
828
- id : id. into_u64 ( ) ,
829
- at : self . base_time . to_system_time ( now) ,
830
- } ) ;
831
- }
809
+ self . current_spans
810
+ . get_or_default ( )
811
+ . borrow_mut ( )
812
+ . push ( id. clone ( ) ) ;
813
+
814
+ self . record ( || record:: Event :: Enter {
815
+ id : id. into_u64 ( ) ,
816
+ at : self . base_time . to_system_time ( now) ,
817
+ } ) ;
832
818
}
833
819
}
834
820
835
821
fn on_exit ( & self , id : & span:: Id , cx : Context < ' _ , S > ) {
836
- fn update < S : Subscriber + for < ' a > LookupSpan < ' a > > (
837
- span : & SpanRef < S > ,
838
- at : Option < Instant > ,
839
- ) -> Option < Instant > {
822
+ if let Some ( span) = cx. span ( id) {
840
823
let exts = span. extensions ( ) ;
824
+ let now = Instant :: now ( ) ;
841
825
// if the span we are entering is a task or async op, record the
842
826
// poll stats.
843
827
if let Some ( stats) = exts. get :: < Arc < stats:: TaskStats > > ( ) {
844
- let at = at. unwrap_or_else ( Instant :: now) ;
845
- stats. end_poll ( at) ;
846
- Some ( at)
828
+ stats. end_poll ( now) ;
847
829
} else if let Some ( stats) = exts. get :: < Arc < stats:: AsyncOpStats > > ( ) {
848
- let at = at. unwrap_or_else ( Instant :: now) ;
849
- stats. end_poll ( at) ;
850
- Some ( at)
830
+ stats. end_poll ( now) ;
831
+ } else if exts. get :: < Arc < stats:: ResourceStats > > ( ) . is_some ( ) {
851
832
// otherwise, is the span a resource? in that case, we also want
852
833
// to enter it, although we don't care about recording poll
853
834
// stats.
854
- } else if exts. get :: < Arc < stats:: ResourceStats > > ( ) . is_some ( ) {
855
- Some ( at. unwrap_or_else ( Instant :: now) )
856
835
} else {
857
- None
858
- }
859
- }
836
+ return ;
837
+ } ;
860
838
861
- if let Some ( span) = cx. span ( id) {
862
- if let Some ( now) = update ( & span, None ) {
863
- if let Some ( parent) = span. parent ( ) {
864
- update ( & parent, Some ( now) ) ;
865
- }
866
- self . current_spans . get_or_default ( ) . borrow_mut ( ) . pop ( id) ;
839
+ self . current_spans . get_or_default ( ) . borrow_mut ( ) . pop ( id) ;
867
840
868
- self . record ( || record:: Event :: Exit {
869
- id : id. into_u64 ( ) ,
870
- at : self . base_time . to_system_time ( now) ,
871
- } ) ;
872
- }
841
+ self . record ( || record:: Event :: Exit {
842
+ id : id. into_u64 ( ) ,
843
+ at : self . base_time . to_system_time ( now) ,
844
+ } ) ;
873
845
}
874
846
}
875
847
0 commit comments