11use super :: {
2- default_headers, default_protocol, parse_header_string,
2+ default_headers, default_protocol, parse_header_string, ExporterBuildError ,
33 OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
44} ;
55use crate :: {
@@ -108,7 +108,7 @@ impl HttpExporterBuilder {
108108 signal_endpoint_path : & str ,
109109 signal_timeout_var : & str ,
110110 signal_http_headers_var : & str ,
111- ) -> Result < OtlpHttpClient , crate :: Error > {
111+ ) -> Result < OtlpHttpClient , ExporterBuildError > {
112112 let endpoint = resolve_http_endpoint (
113113 signal_endpoint_var,
114114 signal_endpoint_path,
@@ -168,12 +168,12 @@ impl HttpExporterBuilder {
168168 . unwrap_or_else ( |_| reqwest:: blocking:: Client :: new ( ) )
169169 } )
170170 . join ( )
171- . unwrap ( ) , // Unwrap thread result
171+ . unwrap ( ) , // TODO: Return ExporterBuildError::ThreadSpawnFailed
172172 ) as Arc < dyn HttpClient > ) ;
173173 }
174174 }
175175
176- let http_client = http_client. ok_or ( crate :: Error :: NoHttpClient ) ?;
176+ let http_client = http_client. ok_or ( ExporterBuildError :: NoHttpClient ) ?;
177177
178178 #[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
179179 let mut headers: HashMap < HeaderName , HeaderValue > = self
@@ -208,9 +208,7 @@ impl HttpExporterBuilder {
208208
209209 /// Create a log exporter with the current configuration
210210 #[ cfg( feature = "trace" ) ]
211- pub fn build_span_exporter (
212- mut self ,
213- ) -> Result < crate :: SpanExporter , opentelemetry_sdk:: trace:: TraceError > {
211+ pub fn build_span_exporter ( mut self ) -> Result < crate :: SpanExporter , ExporterBuildError > {
214212 use crate :: {
215213 OTEL_EXPORTER_OTLP_TRACES_ENDPOINT , OTEL_EXPORTER_OTLP_TRACES_HEADERS ,
216214 OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ,
@@ -228,7 +226,7 @@ impl HttpExporterBuilder {
228226
229227 /// Create a log exporter with the current configuration
230228 #[ cfg( feature = "logs" ) ]
231- pub fn build_log_exporter ( mut self ) -> opentelemetry_sdk :: logs :: LogResult < crate :: LogExporter > {
229+ pub fn build_log_exporter ( mut self ) -> Result < crate :: LogExporter , ExporterBuildError > {
232230 use crate :: {
233231 OTEL_EXPORTER_OTLP_LOGS_ENDPOINT , OTEL_EXPORTER_OTLP_LOGS_HEADERS ,
234232 OTEL_EXPORTER_OTLP_LOGS_TIMEOUT ,
@@ -249,7 +247,7 @@ impl HttpExporterBuilder {
249247 pub fn build_metrics_exporter (
250248 mut self ,
251249 temporality : opentelemetry_sdk:: metrics:: Temporality ,
252- ) -> opentelemetry_sdk :: metrics :: MetricResult < crate :: MetricExporter > {
250+ ) -> Result < crate :: MetricExporter , ExporterBuildError > {
253251 use crate :: {
254252 OTEL_EXPORTER_OTLP_METRICS_ENDPOINT , OTEL_EXPORTER_OTLP_METRICS_HEADERS ,
255253 OTEL_EXPORTER_OTLP_METRICS_TIMEOUT ,
@@ -309,7 +307,7 @@ impl OtlpHttpClient {
309307 match self . protocol {
310308 #[ cfg( feature = "http-json" ) ]
311309 Protocol :: HttpJson => match serde_json:: to_string_pretty ( & req) {
312- Ok ( json) => Ok ( ( json. into ( ) , "application/json" ) ) ,
310+ Ok ( json) => Ok ( ( json. into_bytes ( ) , "application/json" ) ) ,
313311 Err ( e) => Err ( opentelemetry_sdk:: trace:: TraceError :: from ( e. to_string ( ) ) ) ,
314312 } ,
315313 _ => Ok ( ( req. encode_to_vec ( ) , "application/x-protobuf" ) ) ,
@@ -320,7 +318,7 @@ impl OtlpHttpClient {
320318 fn build_logs_export_body (
321319 & self ,
322320 logs : LogBatch < ' _ > ,
323- ) -> opentelemetry_sdk :: logs :: LogResult < ( Vec < u8 > , & ' static str ) > {
321+ ) -> Result < ( Vec < u8 > , & ' static str ) , String > {
324322 use opentelemetry_proto:: tonic:: collector:: logs:: v1:: ExportLogsServiceRequest ;
325323 let resource_logs = group_logs_by_resource_and_scope ( logs, & self . resource ) ;
326324 let req = ExportLogsServiceRequest { resource_logs } ;
@@ -329,7 +327,7 @@ impl OtlpHttpClient {
329327 #[ cfg( feature = "http-json" ) ]
330328 Protocol :: HttpJson => match serde_json:: to_string_pretty ( & req) {
331329 Ok ( json) => Ok ( ( json. into ( ) , "application/json" ) ) ,
332- Err ( e) => Err ( opentelemetry_sdk :: logs :: LogError :: from ( e. to_string ( ) ) ) ,
330+ Err ( e) => Err ( e. to_string ( ) ) ,
333331 } ,
334332 _ => Ok ( ( req. encode_to_vec ( ) , "application/x-protobuf" ) ) ,
335333 }
@@ -357,21 +355,24 @@ impl OtlpHttpClient {
357355 }
358356}
359357
360- fn build_endpoint_uri ( endpoint : & str , path : & str ) -> Result < Uri , crate :: Error > {
358+ fn build_endpoint_uri ( endpoint : & str , path : & str ) -> Result < Uri , ExporterBuildError > {
361359 let path = if endpoint. ends_with ( '/' ) && path. starts_with ( '/' ) {
362360 path. strip_prefix ( '/' ) . unwrap ( )
363361 } else {
364362 path
365363 } ;
366- format ! ( "{endpoint}{path}" ) . parse ( ) . map_err ( From :: from)
364+ let endpoint = format ! ( "{endpoint}{path}" ) ;
365+ endpoint. parse ( ) . map_err ( |er : http:: uri:: InvalidUri | {
366+ ExporterBuildError :: InvalidUri ( endpoint, er. to_string ( ) )
367+ } )
367368}
368369
369370// see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp
370371fn resolve_http_endpoint (
371372 signal_endpoint_var : & str ,
372373 signal_endpoint_path : & str ,
373374 provided_endpoint : Option < String > ,
374- ) -> Result < Uri , crate :: Error > {
375+ ) -> Result < Uri , ExporterBuildError > {
375376 // per signal env var is not modified
376377 if let Some ( endpoint) = env:: var ( signal_endpoint_var)
377378 . ok ( )
@@ -388,14 +389,18 @@ fn resolve_http_endpoint(
388389 return Ok ( endpoint) ;
389390 }
390391
391- provided_endpoint
392- . map ( |e| e. parse ( ) . map_err ( From :: from) )
393- . unwrap_or_else ( || {
394- build_endpoint_uri (
395- OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
396- signal_endpoint_path,
397- )
398- } )
392+ if let Some ( provider_endpoint) = provided_endpoint {
393+ provider_endpoint
394+ . parse ( )
395+ . map_err ( |er : http:: uri:: InvalidUri | {
396+ ExporterBuildError :: InvalidUri ( provider_endpoint, er. to_string ( ) )
397+ } )
398+ } else {
399+ build_endpoint_uri (
400+ OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
401+ signal_endpoint_path,
402+ )
403+ }
399404}
400405
401406#[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
0 commit comments