@@ -90,6 +90,21 @@ pub trait Marker {
90
90
/// If you do see unexpected calls to this method, make sure you're not registering
91
91
/// multiple different schemas with the same [`RuntimeSchemaMarkerSchema::type_name`].
92
92
fn number_field_value ( & self , field_index : u32 ) -> f64 ;
93
+
94
+ /// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
95
+ /// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::Flow`].
96
+ ///
97
+ /// `field_index` is an index into the schema's [`fields`](RuntimeSchemaMarkerSchema::fields).
98
+ ///
99
+ /// Flow identifiers are u64 values that are unique across processes.
100
+ ///
101
+ /// You can panic for any unexpected field indexes, for example
102
+ /// using `unreachable!()`. You can even panic unconditionally if this
103
+ /// marker type doesn't have any flow fields.
104
+ ///
105
+ /// If you do see unexpected calls to this method, make sure you're not registering
106
+ /// multiple different schemas with the same [`RuntimeSchemaMarkerSchema::type_name`].
107
+ fn flow_field_value ( & self , field_index : u32 ) -> u64 ;
93
108
}
94
109
95
110
/// The trait for markers whose schema is known at compile time. Any type which implements
@@ -140,6 +155,10 @@ pub trait Marker {
140
155
/// fn number_field_value(&self, _field_index: u32) -> f64 {
141
156
/// unreachable!()
142
157
/// }
158
+ ///
159
+ /// fn flow_field_value(&self, _field_index: u32) -> u64 {
160
+ /// unreachable!()
161
+ /// }
143
162
/// }
144
163
/// ```
145
164
pub trait StaticSchemaMarker {
@@ -225,6 +244,21 @@ pub trait StaticSchemaMarker {
225
244
/// If you do see unexpected calls to this method, make sure you're not registering
226
245
/// multiple different schemas with the same [`RuntimeSchemaMarkerSchema::type_name`].
227
246
fn number_field_value ( & self , field_index : u32 ) -> f64 ;
247
+
248
+ /// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
249
+ /// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::Flow`].
250
+ ///
251
+ /// `field_index` is an index into the schema's [`fields`](RuntimeSchemaMarkerSchema::fields).
252
+ ///
253
+ /// Flow identifiers are u64 values that are unique across processes.
254
+ ///
255
+ /// You can panic for any unexpected field indexes, for example
256
+ /// using `unreachable!()`. You can even panic unconditionally if this
257
+ /// marker type doesn't have any flow fields.
258
+ ///
259
+ /// If you do see unexpected calls to this method, make sure you're not registering
260
+ /// multiple different schemas with the same [`RuntimeSchemaMarkerSchema::type_name`].
261
+ fn flow_field_value ( & self , field_index : u32 ) -> u64 ;
228
262
}
229
263
230
264
impl < T : StaticSchemaMarker > Marker for T {
@@ -243,6 +277,10 @@ impl<T: StaticSchemaMarker> Marker for T {
243
277
fn number_field_value ( & self , field_index : u32 ) -> f64 {
244
278
<T as StaticSchemaMarker >:: number_field_value ( self , field_index)
245
279
}
280
+
281
+ fn flow_field_value ( & self , field_index : u32 ) -> u64 {
282
+ <T as StaticSchemaMarker >:: flow_field_value ( self , field_index)
283
+ }
246
284
}
247
285
248
286
/// Describes a marker type, including the names and types of the marker's fields.
@@ -510,20 +548,33 @@ pub enum MarkerFieldFormat {
510
548
///
511
549
/// "Label: 52.23, 0.0054, 123,456.78"
512
550
Decimal ,
551
+
552
+ /// A flow is a u64 identifier that's unique across processes. All of
553
+ /// the markers with same flow id before a terminating flow id will be
554
+ /// considered part of the same "flow" and linked together.
555
+ #[ serde( rename = "flow-id" ) ]
556
+ Flow ,
557
+
558
+ /// A terminating flow ends a flow of a particular id and allows that id
559
+ /// to be reused again. It often makes sense for destructors to create
560
+ /// a marker with a field of this type.
561
+ #[ serde( rename = "terminating-flow-id" ) ]
562
+ TerminatingFlow ,
513
563
}
514
564
515
- /// The kind of a marker field. Every marker field is either a string or a number .
565
+ /// The kind of a marker field. Every marker field is either a string, a number, or a flow .
516
566
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
517
567
pub enum MarkerFieldFormatKind {
518
568
String ,
519
569
Number ,
570
+ Flow ,
520
571
}
521
572
522
573
impl MarkerFieldFormat {
523
- /// Whether this field is a number field or a string field.
574
+ /// Whether this field is a number field, a string field, or a flow field.
524
575
///
525
- /// This determines whether we call `number_field_value` or
526
- /// `string_field_value ` to get the field values.
576
+ /// This determines whether we call `number_field_value`, `string_field_value`,
577
+ /// or `flow_field_value ` to get the field values.
527
578
pub fn kind ( & self ) -> MarkerFieldFormatKind {
528
579
match self {
529
580
Self :: Url | Self :: FilePath | Self :: SanitizedString | Self :: String => {
@@ -539,6 +590,7 @@ impl MarkerFieldFormat {
539
590
| Self :: Percentage
540
591
| Self :: Integer
541
592
| Self :: Decimal => MarkerFieldFormatKind :: Number ,
593
+ Self :: Flow | Self :: TerminatingFlow => MarkerFieldFormatKind :: Flow ,
542
594
}
543
595
}
544
596
}
@@ -647,6 +699,7 @@ pub struct InternalMarkerSchema {
647
699
648
700
string_field_count : usize ,
649
701
number_field_count : usize ,
702
+ flow_field_count : usize ,
650
703
651
704
description : Option < String > ,
652
705
}
@@ -669,6 +722,11 @@ impl InternalMarkerSchema {
669
722
. iter ( )
670
723
. filter ( |f| f. format . kind ( ) == MarkerFieldFormatKind :: Number )
671
724
. count ( ) ;
725
+ let flow_field_count = schema
726
+ . fields
727
+ . iter ( )
728
+ . filter ( |f| f. format . kind ( ) == MarkerFieldFormatKind :: Flow )
729
+ . count ( ) ;
672
730
Self {
673
731
type_name : schema. type_name ,
674
732
category : schema. category ,
@@ -680,6 +738,7 @@ impl InternalMarkerSchema {
680
738
graphs : schema. graphs ,
681
739
string_field_count,
682
740
number_field_count,
741
+ flow_field_count,
683
742
description : schema. description ,
684
743
}
685
744
}
@@ -693,6 +752,10 @@ impl InternalMarkerSchema {
693
752
. iter ( )
694
753
. filter ( |f| f. format . kind ( ) == MarkerFieldFormatKind :: Number )
695
754
. count ( ) ;
755
+ let flow_field_count = T :: FIELDS
756
+ . iter ( )
757
+ . filter ( |f| f. format . kind ( ) == MarkerFieldFormatKind :: Flow )
758
+ . count ( ) ;
696
759
Self {
697
760
type_name : T :: UNIQUE_MARKER_TYPE_NAME . into ( ) ,
698
761
category : profile. handle_for_category ( T :: CATEGORY ) ,
@@ -703,6 +766,7 @@ impl InternalMarkerSchema {
703
766
fields : T :: FIELDS . iter ( ) . map ( Into :: into) . collect ( ) ,
704
767
string_field_count,
705
768
number_field_count,
769
+ flow_field_count,
706
770
description : T :: DESCRIPTION . map ( Into :: into) ,
707
771
graphs : T :: GRAPHS . iter ( ) . map ( Into :: into) . collect ( ) ,
708
772
}
@@ -723,6 +787,9 @@ impl InternalMarkerSchema {
723
787
pub fn number_field_count ( & self ) -> usize {
724
788
self . number_field_count
725
789
}
790
+ pub fn flow_field_count ( & self ) -> usize {
791
+ self . flow_field_count
792
+ }
726
793
fn serialize_self < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
727
794
where
728
795
S : serde:: Serializer ,
0 commit comments