1
1
// SPDX-License-Identifier: MIT
2
2
// SPDX-FileCopyrightText: Copyright (c) 2020 Thoren Paulson
3
- //! This file is taken unmodified from the following link, except for file attributes and
4
- //! `extern crate` at the top.
3
+ //! This file was initially taken from the following link, the changes that were made to the
4
+ //! original file can be found in git history (`git log -- path/to/tracing_chrome.rs`):
5
5
//! https://github.com/thoren-d/tracing-chrome/blob/7e2625ab4aeeef2f0ef9bde9d6258dd181c04472/src/lib.rs
6
6
//! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it
7
7
//! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would
@@ -86,6 +86,13 @@ pub enum TraceStyle {
86
86
#[ default]
87
87
Threaded ,
88
88
89
+ /// Like [TraceStyle::Threaded], except that spans whose name is in
90
+ /// [TraceStyle::ThreadedWithExceptions::separate_span_names] will be grouped by name separately
91
+ /// than all other spans.
92
+ ThreadedWithExceptions {
93
+ separate_span_names : Vec < String >
94
+ } ,
95
+
89
96
/// Traces will recorded as a group of asynchronous operations.
90
97
Async ,
91
98
}
@@ -497,31 +504,38 @@ where
497
504
}
498
505
}
499
506
500
- fn get_root_id ( span : SpanRef < S > ) -> u64 {
501
- span. scope ( )
502
- . from_root ( )
503
- . take ( 1 )
504
- . next ( )
505
- . unwrap_or ( span)
506
- . id ( )
507
- . into_u64 ( )
507
+ fn get_root_id ( & self , span : SpanRef < S > ) -> Option < u64 > {
508
+ match & self . trace_style {
509
+ TraceStyle :: Async => Some (
510
+ span. scope ( )
511
+ . from_root ( )
512
+ . take ( 1 )
513
+ . next ( )
514
+ . unwrap_or ( span)
515
+ . id ( )
516
+ . into_u64 ( )
517
+ ) ,
518
+ TraceStyle :: ThreadedWithExceptions { separate_span_names } => {
519
+ let span_name = span. metadata ( ) . name ( ) ;
520
+ // This returns None if a span is not in the list, making all such spans appear on a
521
+ // separate line. Furthermore, the `pos + 1` is because root_id must be > 0.
522
+ separate_span_names. iter ( )
523
+ . position ( |r| r == span_name)
524
+ . map ( |pos| ( pos + 1 ) as u64 )
525
+ }
526
+ TraceStyle :: Threaded => None ,
527
+ }
508
528
}
509
529
510
530
fn enter_span ( & self , span : SpanRef < S > , ts : f64 ) {
511
531
let callsite = self . get_callsite ( EventOrSpan :: Span ( & span) ) ;
512
- let root_id = match self . trace_style {
513
- TraceStyle :: Async => Some ( ChromeLayer :: get_root_id ( span) ) ,
514
- _ => None ,
515
- } ;
532
+ let root_id = self . get_root_id ( span) ;
516
533
self . send_message ( Message :: Enter ( ts, callsite, root_id) ) ;
517
534
}
518
535
519
536
fn exit_span ( & self , span : SpanRef < S > , ts : f64 ) {
520
537
let callsite = self . get_callsite ( EventOrSpan :: Span ( & span) ) ;
521
- let root_id = match self . trace_style {
522
- TraceStyle :: Async => Some ( ChromeLayer :: get_root_id ( span) ) ,
523
- _ => None ,
524
- } ;
538
+ let root_id = self . get_root_id ( span) ;
525
539
self . send_message ( Message :: Exit ( ts, callsite, root_id) ) ;
526
540
}
527
541
@@ -591,7 +605,7 @@ where
591
605
args : Arc :: new ( args) ,
592
606
} ) ;
593
607
}
594
- if let TraceStyle :: Threaded = self . trace_style {
608
+ if ! matches ! ( self . trace_style , TraceStyle :: Async ) {
595
609
return ;
596
610
}
597
611
@@ -600,7 +614,7 @@ where
600
614
}
601
615
602
616
fn on_close ( & self , id : span:: Id , ctx : Context < ' _ , S > ) {
603
- if let TraceStyle :: Threaded = self . trace_style {
617
+ if ! matches ! ( self . trace_style , TraceStyle :: Async ) {
604
618
return ;
605
619
}
606
620
0 commit comments