@@ -85,15 +85,23 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8585 . with_description ( "My histogram example description" )
8686 . build ( ) ;
8787
88- // Record measurements using the histogram instrument.
89- // This metric will have a cardinality limit of 2,
90- // as set in the view. Because of this, only the first two
91- // measurements will be recorded, and the rest will be folded
92- // into the overflow attribute.
88+ // Record measurements using the histogram instrument. This metric will have
89+ // a cardinality limit of 2, as set in the view. Because of this, only the
90+ // first two distinct attribute combinations will be recorded, and the rest
91+ // will be folded into the overflow attribute. Any number of measurements
92+ // can be recorded as long as they use the same or already-seen attribute
93+ // combinations.
9394 histogram2. record ( 1.5 , & [ KeyValue :: new ( "mykey1" , "v1" ) ] ) ;
94-
9595 histogram2. record ( 1.2 , & [ KeyValue :: new ( "mykey1" , "v2" ) ] ) ;
9696
97+ // Repeatedly emitting measurements for "v1" and "v2" will not
98+ // trigger overflow, as they are already seen attribute combinations.
99+ histogram2. record ( 1.7 , & [ KeyValue :: new ( "mykey1" , "v1" ) ] ) ;
100+ histogram2. record ( 1.8 , & [ KeyValue :: new ( "mykey1" , "v2" ) ] ) ;
101+
102+ // Emitting measurements for new attribute combinations will trigger
103+ // overflow, as the cardinality limit of 2 has been reached.
104+ // All the below measurements will be folded into the overflow attribute.
97105 histogram2. record ( 1.23 , & [ KeyValue :: new ( "mykey1" , "v3" ) ] ) ;
98106
99107 histogram2. record ( 1.4 , & [ KeyValue :: new ( "mykey1" , "v4" ) ] ) ;
@@ -104,9 +112,9 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
104112
105113 histogram2. record ( 1.8 , & [ KeyValue :: new ( "mykey1" , "v7" ) ] ) ;
106114
107- // Metrics are exported by default every 30 seconds when using stdout exporter,
115+ // Metrics are exported by default every 60 seconds when using stdout exporter,
108116 // however shutting down the MeterProvider here instantly flushes
109- // the metrics, instead of waiting for the 30 sec interval.
117+ // the metrics, instead of waiting for the 60 sec interval.
110118 meter_provider. shutdown ( ) ?;
111119 Ok ( ( ) )
112120}
0 commit comments