1
1
use super :: {
2
- default_headers, default_protocol, parse_header_string,
2
+ default_headers, default_protocol, parse_header_string, ExporterBuildError ,
3
3
OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT ,
4
4
} ;
5
5
use crate :: {
@@ -108,7 +108,7 @@ impl HttpExporterBuilder {
108
108
signal_endpoint_path : & str ,
109
109
signal_timeout_var : & str ,
110
110
signal_http_headers_var : & str ,
111
- ) -> Result < OtlpHttpClient , crate :: Error > {
111
+ ) -> Result < OtlpHttpClient , ExporterBuildError > {
112
112
let endpoint = resolve_http_endpoint (
113
113
signal_endpoint_var,
114
114
signal_endpoint_path,
@@ -168,12 +168,12 @@ impl HttpExporterBuilder {
168
168
. unwrap_or_else ( |_| reqwest:: blocking:: Client :: new ( ) )
169
169
} )
170
170
. join ( )
171
- . unwrap ( ) , // Unwrap thread result
171
+ . unwrap ( ) , // TODO: Return ExporterBuildError::ThreadSpawnFailed
172
172
) as Arc < dyn HttpClient > ) ;
173
173
}
174
174
}
175
175
176
- let http_client = http_client. ok_or ( crate :: Error :: NoHttpClient ) ?;
176
+ let http_client = http_client. ok_or ( ExporterBuildError :: NoHttpClient ) ?;
177
177
178
178
#[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
179
179
let mut headers: HashMap < HeaderName , HeaderValue > = self
@@ -208,9 +208,7 @@ impl HttpExporterBuilder {
208
208
209
209
/// Create a log exporter with the current configuration
210
210
#[ 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 > {
214
212
use crate :: {
215
213
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT , OTEL_EXPORTER_OTLP_TRACES_HEADERS ,
216
214
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ,
@@ -228,7 +226,7 @@ impl HttpExporterBuilder {
228
226
229
227
/// Create a log exporter with the current configuration
230
228
#[ 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 > {
232
230
use crate :: {
233
231
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT , OTEL_EXPORTER_OTLP_LOGS_HEADERS ,
234
232
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT ,
@@ -249,7 +247,7 @@ impl HttpExporterBuilder {
249
247
pub fn build_metrics_exporter (
250
248
mut self ,
251
249
temporality : opentelemetry_sdk:: metrics:: Temporality ,
252
- ) -> opentelemetry_sdk :: metrics :: MetricResult < crate :: MetricExporter > {
250
+ ) -> Result < crate :: MetricExporter , ExporterBuildError > {
253
251
use crate :: {
254
252
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT , OTEL_EXPORTER_OTLP_METRICS_HEADERS ,
255
253
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT ,
@@ -309,7 +307,7 @@ impl OtlpHttpClient {
309
307
match self . protocol {
310
308
#[ cfg( feature = "http-json" ) ]
311
309
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" ) ) ,
313
311
Err ( e) => Err ( opentelemetry_sdk:: trace:: TraceError :: from ( e. to_string ( ) ) ) ,
314
312
} ,
315
313
_ => Ok ( ( req. encode_to_vec ( ) , "application/x-protobuf" ) ) ,
@@ -320,7 +318,7 @@ impl OtlpHttpClient {
320
318
fn build_logs_export_body (
321
319
& self ,
322
320
logs : LogBatch < ' _ > ,
323
- ) -> opentelemetry_sdk :: logs :: LogResult < ( Vec < u8 > , & ' static str ) > {
321
+ ) -> Result < ( Vec < u8 > , & ' static str ) , String > {
324
322
use opentelemetry_proto:: tonic:: collector:: logs:: v1:: ExportLogsServiceRequest ;
325
323
let resource_logs = group_logs_by_resource_and_scope ( logs, & self . resource ) ;
326
324
let req = ExportLogsServiceRequest { resource_logs } ;
@@ -329,7 +327,7 @@ impl OtlpHttpClient {
329
327
#[ cfg( feature = "http-json" ) ]
330
328
Protocol :: HttpJson => match serde_json:: to_string_pretty ( & req) {
331
329
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 ( ) ) ,
333
331
} ,
334
332
_ => Ok ( ( req. encode_to_vec ( ) , "application/x-protobuf" ) ) ,
335
333
}
@@ -357,21 +355,24 @@ impl OtlpHttpClient {
357
355
}
358
356
}
359
357
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 > {
361
359
let path = if endpoint. ends_with ( '/' ) && path. starts_with ( '/' ) {
362
360
path. strip_prefix ( '/' ) . unwrap ( )
363
361
} else {
364
362
path
365
363
} ;
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
+ } )
367
368
}
368
369
369
370
// see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp
370
371
fn resolve_http_endpoint (
371
372
signal_endpoint_var : & str ,
372
373
signal_endpoint_path : & str ,
373
374
provided_endpoint : Option < String > ,
374
- ) -> Result < Uri , crate :: Error > {
375
+ ) -> Result < Uri , ExporterBuildError > {
375
376
// per signal env var is not modified
376
377
if let Some ( endpoint) = env:: var ( signal_endpoint_var)
377
378
. ok ( )
@@ -388,14 +389,18 @@ fn resolve_http_endpoint(
388
389
return Ok ( endpoint) ;
389
390
}
390
391
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
+ }
399
404
}
400
405
401
406
#[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
0 commit comments