File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
opentelemetry-otlp/src/exporter Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -365,7 +365,7 @@ fn resolve_http_endpoint(
365
365
provided_endpoint : Option < & str > ,
366
366
) -> Result < Uri , ExporterBuildError > {
367
367
// programmatic configuration overrides any value set via environment variables
368
- if let Some ( provider_endpoint) = provided_endpoint {
368
+ if let Some ( provider_endpoint) = provided_endpoint. filter ( |s| !s . is_empty ( ) ) {
369
369
provider_endpoint
370
370
. parse ( )
371
371
. map_err ( |er : http:: uri:: InvalidUri | {
@@ -528,6 +528,15 @@ mod tests {
528
528
) ;
529
529
}
530
530
531
+ #[ test]
532
+ fn test_use_default_when_empty_string_for_option ( ) {
533
+ run_env_test ( vec ! [ ] , || {
534
+ let endpoint =
535
+ super :: resolve_http_endpoint ( "non_existent_var" , "/v1/traces" , Some ( "" ) ) . unwrap ( ) ;
536
+ assert_eq ! ( endpoint, "http://localhost:4318/v1/traces" ) ;
537
+ } ) ;
538
+ }
539
+
531
540
#[ test]
532
541
fn test_use_default_when_others_missing ( ) {
533
542
run_env_test ( vec ! [ ] , || {
Original file line number Diff line number Diff line change @@ -225,7 +225,7 @@ impl TonicExporterBuilder {
225
225
// If users for some reason want to use a custom path, they can use env var or builder to pass it
226
226
//
227
227
// programmatic configuration overrides any value set via environment variables
228
- if let Some ( endpoint) = provided_endpoint {
228
+ if let Some ( endpoint) = provided_endpoint. filter ( |s| !s . is_empty ( ) ) {
229
229
endpoint
230
230
} else if let Ok ( endpoint) = env:: var ( default_endpoint_var) {
231
231
endpoint
@@ -666,4 +666,15 @@ mod tests {
666
666
assert_eq ! ( url, "http://localhost:4317" ) ;
667
667
} ) ;
668
668
}
669
+
670
+ #[ test]
671
+ fn test_use_default_when_empty_string_for_option ( ) {
672
+ run_env_test ( vec ! [ ] , || {
673
+ let url = TonicExporterBuilder :: resolve_endpoint (
674
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
675
+ Some ( String :: new ( ) ) ,
676
+ ) ;
677
+ assert_eq ! ( url, "http://localhost:4317" ) ;
678
+ } ) ;
679
+ }
669
680
}
You can’t perform that action at this time.
0 commit comments