@@ -535,13 +535,13 @@ impl Metric {
535535 let data = format ! (
536536 "{}@{}:{}|{}|#{}|T{}" ,
537537 NormalizedName :: from( self . name. as_ref( ) ) ,
538- NormalizedUnit :: from( self . unit) ,
538+ NormalizedUnit :: from( self . unit. to_string ( ) . as_ref ( ) ) ,
539539 self . value,
540540 self . value. ty( ) ,
541- NormalizedTags :: from( self . tags) ,
541+ NormalizedTags :: from( & self . tags) ,
542542 timestamp
543543 ) ;
544- Envelope :: from_item ( EnvelopeItem :: Statsd ( data. into_bytes ( ) ) )
544+ EnvelopeItem :: Statsd ( data. into_bytes ( ) ) . into ( )
545545 }
546546}
547547
@@ -597,9 +597,9 @@ impl MetricBuilder {
597597 K : Into < MetricStr > ,
598598 V : Into < MetricStr > ,
599599 {
600- tags . into_iter ( ) . for_each ( | ( k, v) | {
600+ for ( k, v) in tags {
601601 self . metric . tags . insert ( k. into ( ) , v. into ( ) ) ;
602- } ) ;
602+ }
603603 self
604604 }
605605
@@ -781,6 +781,7 @@ fn get_default_tags(options: &ClientOptions) -> TagMap {
781781 options
782782 . environment
783783 . clone ( )
784+ . filter ( |e| !e. is_empty ( ) )
784785 . unwrap_or ( Cow :: Borrowed ( "production" ) ) ,
785786 ) ;
786787 tags
@@ -836,7 +837,12 @@ impl Worker {
836837 for ( timestamp, buckets) in buckets {
837838 for ( key, value) in buckets {
838839 write ! ( & mut out, "{}" , NormalizedName :: from( key. name. as_ref( ) ) ) ?;
839- write ! ( & mut out, "@{}" , NormalizedUnit :: from( key. unit) ) ?;
840+ match key. unit {
841+ MetricUnit :: Custom ( u) => {
842+ write ! ( & mut out, "@{}" , NormalizedUnit :: from( u. as_ref( ) ) ) ?
843+ }
844+ _ => write ! ( & mut out, "@{}" , key. unit) ?,
845+ }
840846 match value {
841847 BucketValue :: Counter ( c) => {
842848 write ! ( & mut out, ":{}" , c) ?;
@@ -862,7 +868,7 @@ impl Worker {
862868
863869 write ! ( & mut out, "|{}" , key. ty. as_str( ) ) ?;
864870 let normalized_tags =
865- NormalizedTags :: from ( key. tags ) . with_default_tags ( & self . default_tags ) ;
871+ NormalizedTags :: from ( & key. tags ) . with_default_tags ( & self . default_tags ) ;
866872 write ! ( & mut out, "|#{}" , normalized_tags) ?;
867873 writeln ! ( & mut out, "|T{}" , timestamp) ?;
868874 }
@@ -1093,6 +1099,59 @@ mod tests {
10931099 ) ;
10941100 }
10951101
1102+ #[ test]
1103+ fn test_empty_default_tags ( ) {
1104+ let ( time, ts) = current_time ( ) ;
1105+ let options = ClientOptions {
1106+ release : Some ( "" . into ( ) ) ,
1107+ environment : Some ( "" . into ( ) ) ,
1108+ ..Default :: default ( )
1109+ } ;
1110+
1111+ let envelopes = with_captured_envelopes_options (
1112+ || {
1113+ Metric :: count ( "requests" )
1114+ . with_tag ( "foo" , "bar" )
1115+ . with_time ( time)
1116+ . send ( ) ;
1117+ } ,
1118+ options,
1119+ ) ;
1120+
1121+ let metrics = get_single_metrics ( & envelopes) ;
1122+ assert_eq ! (
1123+ metrics,
1124+ format!( "requests@none:1|c|#environment:production,foo:bar|T{ts}" )
1125+ ) ;
1126+ }
1127+
1128+ #[ test]
1129+ fn test_override_default_tags ( ) {
1130+ let ( time, ts) = current_time ( ) ;
1131+ let options = ClientOptions {
1132+ release : Some ( "default_release" . into ( ) ) ,
1133+ environment : Some ( "default_env" . into ( ) ) ,
1134+ ..Default :: default ( )
1135+ } ;
1136+
1137+ let envelopes = with_captured_envelopes_options (
1138+ || {
1139+ Metric :: count ( "requests" )
1140+ . with_tag ( "environment" , "custom_env" )
1141+ . with_tag ( "release" , "custom_release" )
1142+ . with_time ( time)
1143+ . send ( ) ;
1144+ } ,
1145+ options,
1146+ ) ;
1147+
1148+ let metrics = get_single_metrics ( & envelopes) ;
1149+ assert_eq ! (
1150+ metrics,
1151+ format!( "requests@none:1|c|#environment:custom_env,release:custom_release|T{ts}" )
1152+ ) ;
1153+ }
1154+
10961155 #[ test]
10971156 fn test_counter ( ) {
10981157 let ( time, ts) = current_time ( ) ;
0 commit comments