@@ -153,10 +153,10 @@ impl HttpExporterBuilder {
153
153
signal_timeout_var : & str ,
154
154
signal_http_headers_var : & str ,
155
155
) -> Result < OtlpHttpClient , crate :: Error > {
156
- let endpoint = resolve_endpoint (
156
+ let endpoint = resolve_http_endpoint (
157
157
signal_endpoint_var,
158
158
signal_endpoint_path,
159
- self . exporter_config . endpoint . as_deref ( ) ,
159
+ self . exporter_config . endpoint . as_str ( ) ,
160
160
) ?;
161
161
162
162
let timeout = match env:: var ( signal_timeout_var)
@@ -376,10 +376,10 @@ fn build_endpoint_uri(endpoint: &str, path: &str) -> Result<Uri, crate::Error> {
376
376
}
377
377
378
378
// see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp
379
- fn resolve_endpoint (
379
+ fn resolve_http_endpoint (
380
380
signal_endpoint_var : & str ,
381
381
signal_endpoint_path : & str ,
382
- provided_endpoint : Option < & str > ,
382
+ provided_endpoint : & str ,
383
383
) -> Result < Uri , crate :: Error > {
384
384
// per signal env var is not modified
385
385
if let Some ( endpoint) = env:: var ( signal_endpoint_var)
@@ -397,12 +397,13 @@ fn resolve_endpoint(
397
397
return Ok ( endpoint) ;
398
398
}
399
399
400
- match provided_endpoint {
401
- Some ( endpoint) => build_endpoint_uri ( endpoint, "" ) ,
402
- None => build_endpoint_uri (
400
+ if provided_endpoint. is_empty ( ) {
401
+ build_endpoint_uri (
403
402
OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
404
403
signal_endpoint_path,
405
- ) ,
404
+ )
405
+ } else {
406
+ build_endpoint_uri ( provided_endpoint, "" )
406
407
}
407
408
}
408
409
@@ -424,17 +425,17 @@ mod tests {
424
425
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
425
426
} ;
426
427
427
- use super :: { build_endpoint_uri, resolve_endpoint } ;
428
+ use super :: { build_endpoint_uri, resolve_http_endpoint } ;
428
429
429
430
#[ test]
430
431
fn test_append_signal_path_to_generic_env ( ) {
431
432
run_env_test (
432
433
vec ! [ ( OTEL_EXPORTER_OTLP_ENDPOINT , "http://example.com" ) ] ,
433
434
|| {
434
- let endpoint = resolve_endpoint (
435
+ let endpoint = resolve_http_endpoint (
435
436
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
436
437
"/v1/traces" ,
437
- Some ( "http://localhost:4317" ) ,
438
+ "http://localhost:4317" ,
438
439
)
439
440
. unwrap ( ) ;
440
441
assert_eq ! ( endpoint, "http://example.com/v1/traces" ) ;
@@ -447,10 +448,10 @@ mod tests {
447
448
run_env_test (
448
449
vec ! [ ( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT , "http://example.com" ) ] ,
449
450
|| {
450
- let endpoint = super :: resolve_endpoint (
451
+ let endpoint = super :: resolve_http_endpoint (
451
452
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
452
453
"/v1/traces" ,
453
- Some ( "http://localhost:4317" ) ,
454
+ "http://localhost:4317" ,
454
455
)
455
456
. unwrap ( ) ;
456
457
assert_eq ! ( endpoint, "http://example.com" ) ;
@@ -466,10 +467,10 @@ mod tests {
466
467
( OTEL_EXPORTER_OTLP_ENDPOINT , "http://wrong.com" ) ,
467
468
] ,
468
469
|| {
469
- let endpoint = super :: resolve_endpoint (
470
+ let endpoint = super :: resolve_http_endpoint (
470
471
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
471
472
"/v1/traces" ,
472
- Some ( "http://localhost:4317" ) ,
473
+ "http://localhost:4317" ,
473
474
)
474
475
. unwrap ( ) ;
475
476
assert_eq ! ( endpoint, "http://example.com" ) ;
@@ -480,10 +481,10 @@ mod tests {
480
481
#[ test]
481
482
fn test_use_provided_or_default_when_others_missing ( ) {
482
483
run_env_test ( vec ! [ ] , || {
483
- let endpoint = super :: resolve_endpoint (
484
+ let endpoint = super :: resolve_http_endpoint (
484
485
"NON_EXISTENT_VAR" ,
485
486
"/v1/traces" ,
486
- Some ( "http://localhost:4317" ) ,
487
+ "http://localhost:4317" ,
487
488
)
488
489
. unwrap ( ) ;
489
490
assert_eq ! ( endpoint, "http://localhost:4317/" ) ;
@@ -515,10 +516,10 @@ mod tests {
515
516
( OTEL_EXPORTER_OTLP_ENDPOINT , "http://example.com" ) ,
516
517
] ,
517
518
|| {
518
- let endpoint = super :: resolve_endpoint (
519
+ let endpoint = super :: resolve_http_endpoint (
519
520
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
520
521
"/v1/traces" ,
521
- Some ( "http://localhost:4317" ) ,
522
+ "http://localhost:4317" ,
522
523
)
523
524
. unwrap ( ) ;
524
525
assert_eq ! ( endpoint, "http://example.com/v1/traces" ) ;
@@ -529,10 +530,10 @@ mod tests {
529
530
#[ test]
530
531
fn test_all_invalid_urls_falls_back_to_error ( ) {
531
532
run_env_test ( vec ! [ ] , || {
532
- let result = super :: resolve_endpoint (
533
+ let result = super :: resolve_http_endpoint (
533
534
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
534
535
"/v1/traces" ,
535
- Some ( "-*/*-/*-//-/-/yet-another-invalid-uri" ) ,
536
+ "-*/*-/*-//-/-/yet-another-invalid-uri" ,
536
537
) ;
537
538
assert ! ( result. is_err( ) ) ;
538
539
// You may also want to assert on the specific error type if applicable
@@ -631,10 +632,10 @@ mod tests {
631
632
run_env_test ( vec ! [ ] , || {
632
633
let exporter = new_exporter ( ) . http ( ) ;
633
634
634
- let url = resolve_endpoint (
635
+ let url = resolve_http_endpoint (
635
636
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
636
637
"/v1/traces" ,
637
- exporter. exporter_config . endpoint . as_deref ( ) ,
638
+ exporter. exporter_config . endpoint . as_str ( ) ,
638
639
)
639
640
. unwrap ( ) ;
640
641
@@ -647,10 +648,10 @@ mod tests {
647
648
. http ( )
648
649
. with_endpoint ( "http://localhost:4318/v1/tracesbutnotreally" ) ;
649
650
650
- let url = resolve_endpoint (
651
+ let url = resolve_http_endpoint (
651
652
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
652
653
"/v1/traces" ,
653
- exporter. exporter_config . endpoint . as_deref ( ) ,
654
+ exporter. exporter_config . endpoint . as_str ( ) ,
654
655
)
655
656
. unwrap ( ) ;
656
657
0 commit comments