@@ -127,7 +127,7 @@ impl HttpExporterBuilder {
127127 let endpoint = resolve_http_endpoint (
128128 signal_endpoint_var,
129129 signal_endpoint_path,
130- self . exporter_config . endpoint . as_str ( ) ,
130+ self . exporter_config . endpoint . clone ( ) ,
131131 ) ?;
132132
133133 let timeout = match env:: var ( signal_timeout_var)
@@ -340,7 +340,7 @@ fn build_endpoint_uri(endpoint: &str, path: &str) -> Result<Uri, crate::Error> {
340340fn resolve_http_endpoint (
341341 signal_endpoint_var : & str ,
342342 signal_endpoint_path : & str ,
343- provided_endpoint : & str ,
343+ provided_endpoint : Option < String > ,
344344) -> Result < Uri , crate :: Error > {
345345 // per signal env var is not modified
346346 if let Some ( endpoint) = env:: var ( signal_endpoint_var)
@@ -358,14 +358,14 @@ fn resolve_http_endpoint(
358358 return Ok ( endpoint) ;
359359 }
360360
361- if provided_endpoint. is_empty ( ) {
362- build_endpoint_uri (
363- OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
364- signal_endpoint_path ,
365- )
366- } else {
367- provided_endpoint . parse ( ) . map_err ( From :: from )
368- }
361+ provided_endpoint
362+ . map ( |e| e . parse ( ) . map_err ( From :: from ) )
363+ . unwrap_or_else ( || {
364+ build_endpoint_uri (
365+ OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
366+ signal_endpoint_path ,
367+ )
368+ } )
369369}
370370
371371#[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
@@ -449,7 +449,7 @@ mod tests {
449449 let endpoint = resolve_http_endpoint (
450450 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
451451 "/v1/traces" ,
452- "http://localhost:4317" ,
452+ Some ( "http://localhost:4317" . to_string ( ) ) ,
453453 )
454454 . unwrap ( ) ;
455455 assert_eq ! ( endpoint, "http://example.com/v1/traces" ) ;
@@ -465,7 +465,7 @@ mod tests {
465465 let endpoint = super :: resolve_http_endpoint (
466466 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
467467 "/v1/traces" ,
468- "http://localhost:4317" ,
468+ Some ( "http://localhost:4317" . to_string ( ) ) ,
469469 )
470470 . unwrap ( ) ;
471471 assert_eq ! ( endpoint, "http://example.com" ) ;
@@ -484,7 +484,7 @@ mod tests {
484484 let endpoint = super :: resolve_http_endpoint (
485485 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
486486 "/v1/traces" ,
487- "http://localhost:4317" ,
487+ Some ( "http://localhost:4317" . to_string ( ) ) ,
488488 )
489489 . unwrap ( ) ;
490490 assert_eq ! ( endpoint, "http://example.com" ) ;
@@ -498,7 +498,7 @@ mod tests {
498498 let endpoint = super :: resolve_http_endpoint (
499499 "NON_EXISTENT_VAR" ,
500500 "/v1/traces" ,
501- "http://localhost:4317" ,
501+ Some ( "http://localhost:4317" . to_string ( ) ) ,
502502 )
503503 . unwrap ( ) ;
504504 assert_eq ! ( endpoint, "http://localhost:4317/" ) ;
@@ -533,7 +533,7 @@ mod tests {
533533 let endpoint = super :: resolve_http_endpoint (
534534 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
535535 "/v1/traces" ,
536- "http://localhost:4317" ,
536+ Some ( "http://localhost:4317" . to_string ( ) ) ,
537537 )
538538 . unwrap ( ) ;
539539 assert_eq ! ( endpoint, "http://example.com/v1/traces" ) ;
@@ -547,7 +547,7 @@ mod tests {
547547 let result = super :: resolve_http_endpoint (
548548 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
549549 "/v1/traces" ,
550- "-*/*-/*-//-/-/yet-another-invalid-uri" ,
550+ Some ( "-*/*-/*-//-/-/yet-another-invalid-uri" . to_string ( ) ) ,
551551 ) ;
552552 assert ! ( result. is_err( ) ) ;
553553 // You may also want to assert on the specific error type if applicable
@@ -644,8 +644,8 @@ mod tests {
644644 fn test_http_exporter_builder_with_header ( ) {
645645 use std:: collections:: HashMap ;
646646 // Arrange
647- let initial_headers = [ ( "k1" . to_string ( ) , "v1" . to_string ( ) ) ] ;
648- let extra_headers = [ ( "k2" . to_string ( ) , "v2" . to_string ( ) ) ] ;
647+ let initial_headers = HashMap :: from ( [ ( "k1" . to_string ( ) , "v1" . to_string ( ) ) ] ) ;
648+ let extra_headers = HashMap :: from ( [ ( "k2" . to_string ( ) , "v2" . to_string ( ) ) ] ) ;
649649 let expected_headers = initial_headers. iter ( ) . chain ( extra_headers. iter ( ) ) . fold (
650650 HashMap :: new ( ) ,
651651 |mut acc, ( k, v) | {
@@ -656,13 +656,13 @@ mod tests {
656656 let builder = HttpExporterBuilder {
657657 http_config : HttpConfig {
658658 client : None ,
659- headers : Some ( HashMap :: from ( [ ( "k1" . to_string ( ) , "v1" . to_string ( ) ) ] ) ) ,
659+ headers : Some ( initial_headers ) ,
660660 } ,
661661 exporter_config : crate :: ExportConfig :: default ( ) ,
662662 } ;
663663
664664 // Act
665- let builder = builder. with_headers ( HashMap :: from ( [ ( "k2" . to_string ( ) , "v2" . to_string ( ) ) ] ) ) ;
665+ let builder = builder. with_headers ( extra_headers ) ;
666666
667667 // Assert
668668 assert_eq ! (
@@ -684,7 +684,7 @@ mod tests {
684684 let url = resolve_http_endpoint (
685685 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
686686 "/v1/traces" ,
687- exporter. exporter_config . endpoint . as_str ( ) ,
687+ exporter. exporter_config . endpoint ,
688688 )
689689 . unwrap ( ) ;
690690
@@ -699,7 +699,7 @@ mod tests {
699699 let url = resolve_http_endpoint (
700700 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
701701 "/v1/traces" ,
702- exporter. exporter_config . endpoint . as_str ( ) ,
702+ exporter. exporter_config . endpoint ,
703703 )
704704 . unwrap ( ) ;
705705
0 commit comments