12
12
//! ```rust
13
13
//! tracing::info_span!("my_span", tracing_separate_thread = tracing::field::Empty, /* ... */)
14
14
//! ```
15
+ //! - use i64 instead of u64 for the "id" in [ChromeLayer::get_root_id] to be compatible with Perfetto
15
16
//!
16
17
//! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it
17
18
//! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would
@@ -285,9 +286,9 @@ struct Callsite {
285
286
}
286
287
287
288
enum Message {
288
- Enter ( f64 , Callsite , Option < u64 > ) ,
289
+ Enter ( f64 , Callsite , Option < i64 > ) ,
289
290
Event ( f64 , Callsite ) ,
290
- Exit ( f64 , Callsite , Option < u64 > ) ,
291
+ Exit ( f64 , Callsite , Option < i64 > ) ,
291
292
NewThread ( usize , String ) ,
292
293
Flush ,
293
294
Drop ,
@@ -519,14 +520,17 @@ where
519
520
}
520
521
}
521
522
522
- fn get_root_id ( & self , span : SpanRef < S > ) -> Option < u64 > {
523
+ fn get_root_id ( & self , span : SpanRef < S > ) -> Option < i64 > {
524
+ // Returns `Option<i64>` instead of `Option<u64>` because apparently Perfetto gives an
525
+ // error if an id does not fit in a 64-bit signed integer in 2's complement. We cast the
526
+ // span id from `u64` to `i64` with wraparound, since negative values are fine.
523
527
match self . trace_style {
524
528
TraceStyle :: Threaded => {
525
529
if span. fields ( ) . field ( "tracing_separate_thread" ) . is_some ( ) {
526
530
// assign an independent "id" to spans with argument "tracing_separate_thread",
527
531
// so they appear a separate trace line in trace visualization tools, see
528
532
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1
529
- Some ( span. id ( ) . into_u64 ( ) )
533
+ Some ( span. id ( ) . into_u64 ( ) . cast_signed ( ) ) // the comment above explains the cast
530
534
} else {
531
535
None
532
536
}
@@ -539,6 +543,7 @@ where
539
543
. unwrap_or ( span)
540
544
. id ( )
541
545
. into_u64 ( )
546
+ . cast_signed ( ) // the comment above explains the cast
542
547
) ,
543
548
}
544
549
}
0 commit comments