@@ -52,8 +52,16 @@ impl TryFrom<Compression> for tonic::codec::CompressionEncoding {
52
52
#[ cfg( feature = "gzip-tonic" ) ]
53
53
Compression :: Gzip => Ok ( tonic:: codec:: CompressionEncoding :: Gzip ) ,
54
54
#[ cfg( not( feature = "gzip-tonic" ) ) ]
55
- Compression :: Gzip => Err ( crate :: Error :: UnsupportedCompressionAlgorithm (
56
- value. to_string ( ) ,
55
+ Compression :: Gzip => Err ( crate :: Error :: FeatureRequiredForCompressionAlgorithm (
56
+ "gzip-tonic" ,
57
+ Compression :: Gzip ,
58
+ ) ) ,
59
+ #[ cfg( feature = "zstd-tonic" ) ]
60
+ Compression :: Zstd => Ok ( tonic:: codec:: CompressionEncoding :: Zstd ) ,
61
+ #[ cfg( not( feature = "zstd-tonic" ) ) ]
62
+ Compression :: Zstd => Err ( crate :: Error :: FeatureRequiredForCompressionAlgorithm (
63
+ "zstd-tonic" ,
64
+ Compression :: Zstd ,
57
65
) ) ,
58
66
}
59
67
}
@@ -399,7 +407,7 @@ fn parse_headers_from_env(signal_headers_var: &str) -> HeaderMap {
399
407
#[ cfg( test) ]
400
408
mod tests {
401
409
use crate :: exporter:: tests:: run_env_test;
402
- #[ cfg( feature = "gzip -tonic" ) ]
410
+ #[ cfg( feature = "grpc -tonic" ) ]
403
411
use crate :: exporter:: Compression ;
404
412
use crate :: TonicExporterBuilder ;
405
413
use crate :: { OTEL_EXPORTER_OTLP_HEADERS , OTEL_EXPORTER_OTLP_TRACES_HEADERS } ;
@@ -438,14 +446,34 @@ mod tests {
438
446
439
447
#[ test]
440
448
#[ cfg( feature = "gzip-tonic" ) ]
441
- fn test_with_compression ( ) {
449
+ fn test_with_gzip_compression ( ) {
442
450
// metadata should merge with the current one with priority instead of just replacing it
443
451
let mut metadata = MetadataMap :: new ( ) ;
444
452
metadata. insert ( "foo" , "bar" . parse ( ) . unwrap ( ) ) ;
445
453
let builder = TonicExporterBuilder :: default ( ) . with_compression ( Compression :: Gzip ) ;
446
454
assert_eq ! ( builder. tonic_config. compression. unwrap( ) , Compression :: Gzip ) ;
447
455
}
448
456
457
+ #[ test]
458
+ #[ cfg( feature = "zstd-tonic" ) ]
459
+ fn test_with_zstd_compression ( ) {
460
+ let builder = TonicExporterBuilder :: default ( ) . with_compression ( Compression :: Zstd ) ;
461
+ assert_eq ! ( builder. tonic_config. compression. unwrap( ) , Compression :: Zstd ) ;
462
+ }
463
+
464
+ #[ test]
465
+ #[ cfg( feature = "grpc-tonic" ) ]
466
+ fn test_convert_compression ( ) {
467
+ #[ cfg( feature = "gzip-tonic" ) ]
468
+ assert ! ( tonic:: codec:: CompressionEncoding :: try_from( Compression :: Gzip ) . is_ok( ) ) ;
469
+ #[ cfg( not( feature = "gzip-tonic" ) ) ]
470
+ assert ! ( tonic:: codec:: CompressionEncoding :: try_from( Compression :: Gzip ) . is_err( ) ) ;
471
+ #[ cfg( feature = "zstd-tonic" ) ]
472
+ assert ! ( tonic:: codec:: CompressionEncoding :: try_from( Compression :: Zstd ) . is_ok( ) ) ;
473
+ #[ cfg( not( feature = "zstd-tonic" ) ) ]
474
+ assert ! ( tonic:: codec:: CompressionEncoding :: try_from( Compression :: Zstd ) . is_err( ) ) ;
475
+ }
476
+
449
477
#[ test]
450
478
fn test_parse_headers_from_env ( ) {
451
479
run_env_test (
0 commit comments