@@ -44,15 +44,7 @@ mod trace;
44
44
use opentelemetry_http:: hyper:: HyperClient ;
45
45
46
46
/// Configuration of the http transport
47
- #[ derive( Debug ) ]
48
- #[ cfg_attr(
49
- all(
50
- not( feature = "reqwest-client" ) ,
51
- not( feature = "reqwest-blocking-client" ) ,
52
- not( feature = "hyper-client" )
53
- ) ,
54
- derive( Default )
55
- ) ]
47
+ #[ derive( Debug , Default ) ]
56
48
pub struct HttpConfig {
57
49
/// Select the HTTP client
58
50
client : Option < Arc < dyn HttpClient > > ,
@@ -61,44 +53,6 @@ pub struct HttpConfig {
61
53
headers : Option < HashMap < String , String > > ,
62
54
}
63
55
64
- #[ cfg( any(
65
- feature = "reqwest-blocking-client" ,
66
- feature = "reqwest-client" ,
67
- feature = "hyper-client"
68
- ) ) ]
69
- impl Default for HttpConfig {
70
- fn default ( ) -> Self {
71
- #[ cfg( feature = "reqwest-blocking-client" ) ]
72
- let default_client = std:: thread:: spawn ( || {
73
- Some ( Arc :: new ( reqwest:: blocking:: Client :: new ( ) ) as Arc < dyn HttpClient > )
74
- } )
75
- . join ( )
76
- . expect ( "creating reqwest::blocking::Client on a new thread not to fail" ) ;
77
- #[ cfg( all( not( feature = "reqwest-blocking-client" ) , feature = "reqwest-client" ) ) ]
78
- let default_client = Some ( Arc :: new ( reqwest:: Client :: new ( ) ) as Arc < dyn HttpClient > ) ;
79
- #[ cfg( all(
80
- not( feature = "reqwest-client" ) ,
81
- not( feature = "reqwest-blocking-client" ) ,
82
- feature = "hyper-client"
83
- ) ) ]
84
- // TODO - support configuring custom connector and executor
85
- let default_client = Some ( Arc :: new ( HyperClient :: with_default_connector (
86
- Duration :: from_secs ( 10 ) ,
87
- None ,
88
- ) ) as Arc < dyn HttpClient > ) ;
89
- #[ cfg( all(
90
- not( feature = "reqwest-client" ) ,
91
- not( feature = "reqwest-blocking-client" ) ,
92
- not( feature = "hyper-client" )
93
- ) ) ]
94
- let default_client = None ;
95
- HttpConfig {
96
- client : default_client,
97
- headers : None ,
98
- }
99
- }
100
- }
101
-
102
56
/// Configuration for the OTLP HTTP exporter.
103
57
///
104
58
/// ## Examples
@@ -171,11 +125,56 @@ impl HttpExporterBuilder {
171
125
} ,
172
126
None => self . exporter_config . timeout ,
173
127
} ;
174
- let http_client = self
175
- . http_config
176
- . client
177
- . take ( )
178
- . ok_or ( crate :: Error :: NoHttpClient ) ?;
128
+
129
+ #[ allow( unused_mut) ] // TODO - clippy thinks mut is not needed, but it is
130
+ let mut http_client = self . http_config . client . take ( ) ;
131
+
132
+ if http_client. is_none ( ) {
133
+ #[ cfg( all(
134
+ not( feature = "reqwest-client" ) ,
135
+ not( feature = "reqwest-blocking-client" ) ,
136
+ feature = "hyper-client"
137
+ ) ) ]
138
+ {
139
+ // TODO - support configuring custom connector and executor
140
+ http_client = Some ( Arc :: new ( HyperClient :: with_default_connector ( timeout, None ) )
141
+ as Arc < dyn HttpClient > ) ;
142
+ }
143
+ #[ cfg( all(
144
+ not( feature = "hyper-client" ) ,
145
+ not( feature = "reqwest-blocking-client" ) ,
146
+ feature = "reqwest-client"
147
+ ) ) ]
148
+ {
149
+ http_client = Some ( Arc :: new (
150
+ reqwest:: Client :: builder ( )
151
+ . timeout ( timeout)
152
+ . build ( )
153
+ . unwrap_or_default ( ) ,
154
+ ) as Arc < dyn HttpClient > ) ;
155
+ }
156
+ #[ cfg( all(
157
+ not( feature = "hyper-client" ) ,
158
+ not( feature = "reqwest-client" ) ,
159
+ feature = "reqwest-blocking-client"
160
+ ) ) ]
161
+ {
162
+ let timeout_clone = timeout;
163
+ http_client = Some ( Arc :: new (
164
+ std:: thread:: spawn ( move || {
165
+ reqwest:: blocking:: Client :: builder ( )
166
+ . timeout ( timeout_clone)
167
+ . build ( )
168
+ . unwrap_or_else ( |_| reqwest:: blocking:: Client :: new ( ) )
169
+ } )
170
+ . join ( )
171
+ . unwrap ( ) , // Unwrap thread result
172
+ ) as Arc < dyn HttpClient > ) ;
173
+ }
174
+ }
175
+
176
+ let http_client = http_client. ok_or ( crate :: Error :: NoHttpClient ) ?;
177
+
179
178
#[ allow( clippy:: mutable_key_type) ] // http headers are not mutated
180
179
let mut headers: HashMap < HeaderName , HeaderValue > = self
181
180
. http_config
0 commit comments