@@ -12,20 +12,17 @@ use crate::Protocol;
12
12
use std:: str:: FromStr ;
13
13
use std:: time:: Duration ;
14
14
15
- /// Target to which the exporter is going to send spans or metrics, defaults to https://localhost:4317.
15
+ /// Target to which the exporter is going to send signals, defaults to https://localhost:4317.
16
+ /// Learn about the relationship between this constant and metrics/spans/logs at
17
+ /// <https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp>
16
18
pub const OTEL_EXPORTER_OTLP_ENDPOINT : & str = "OTEL_EXPORTER_OTLP_ENDPOINT" ;
17
- /// Default target to which the exporter is going to send spans or metrics .
19
+ /// Default target to which the exporter is going to send signals .
18
20
pub const OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT : & str = "https://localhost:4317" ;
19
- /// Max waiting time for the backend to process each spans or metrics batch, defaults to 10 seconds.
21
+ /// Max waiting time for the backend to process each signal batch, defaults to 10 seconds.
20
22
pub const OTEL_EXPORTER_OTLP_TIMEOUT : & str = "OTEL_EXPORTER_OTLP_TIMEOUT" ;
21
- /// Default max waiting time for the backend to process each spans or metrics batch.
23
+ /// Default max waiting time for the backend to process each signal batch.
22
24
pub const OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT : u64 = 10 ;
23
25
24
- /// Target to which the exporter is going to send spans, defaults to https://localhost:4317.
25
- pub const OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : & str = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" ;
26
- /// Max waiting time for the backend to process each spans batch, defaults to 10s.
27
- pub const OTEL_EXPORTER_OTLP_TRACES_TIMEOUT : & str = "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT" ;
28
-
29
26
#[ cfg( feature = "grpc-sys" ) ]
30
27
pub ( crate ) mod grpcio;
31
28
#[ cfg( feature = "http-proto" ) ]
@@ -36,7 +33,7 @@ pub(crate) mod tonic;
36
33
/// Configuration for the OTLP exporter.
37
34
#[ derive( Debug ) ]
38
35
pub struct ExportConfig {
39
- /// The address of the OTLP collector. If not set, the default address is used.
36
+ /// The base address of the OTLP collector. If not set, the default address is used.
40
37
pub endpoint : String ,
41
38
42
39
/// The protocol to use when communicating with the collector.
@@ -129,18 +126,15 @@ impl<B: HasExportConfig> WithExportConfig for B {
129
126
}
130
127
131
128
fn with_env ( mut self ) -> Self {
132
- let endpoint = match std:: env:: var ( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ) {
129
+ let endpoint = match std:: env:: var ( OTEL_EXPORTER_OTLP_ENDPOINT ) {
133
130
Ok ( val) => val,
134
- Err ( _) => std:: env:: var ( OTEL_EXPORTER_OTLP_ENDPOINT )
135
- . unwrap_or_else ( |_| OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT . to_string ( ) ) ,
131
+ Err ( _) => OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT . to_string ( ) ,
136
132
} ;
137
133
self . export_config ( ) . endpoint = endpoint;
138
134
139
- let timeout = match std:: env:: var ( OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ) {
135
+ let timeout = match std:: env:: var ( OTEL_EXPORTER_OTLP_TIMEOUT ) {
140
136
Ok ( val) => u64:: from_str ( & val) . unwrap_or ( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ) ,
141
- Err ( _) => std:: env:: var ( OTEL_EXPORTER_OTLP_TIMEOUT )
142
- . map ( |val| u64:: from_str ( & val) . unwrap_or ( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ) )
143
- . unwrap_or ( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ) ,
137
+ Err ( _) => OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ,
144
138
} ;
145
139
self . export_config ( ) . timeout = Duration :: from_secs ( timeout) ;
146
140
self
@@ -159,17 +153,20 @@ impl<B: HasExportConfig> WithExportConfig for B {
159
153
mod tests {
160
154
use crate :: exporter:: {
161
155
WithExportConfig , OTEL_EXPORTER_OTLP_ENDPOINT , OTEL_EXPORTER_OTLP_TIMEOUT ,
162
- OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT , OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
163
- OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ,
156
+ OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ,
164
157
} ;
165
158
use crate :: new_exporter;
166
159
167
160
#[ test]
168
- fn test_pipeline_builder_from_env ( ) {
169
- std:: env:: set_var ( OTEL_EXPORTER_OTLP_ENDPOINT , "https://otlp_endpoint:4317" ) ;
161
+ fn test_pipeline_builder_from_env_default_vars ( ) {
162
+ let expected_endpoint = "https://otlp_endpoint:4317" ;
163
+ std:: env:: set_var ( OTEL_EXPORTER_OTLP_ENDPOINT , expected_endpoint) ;
170
164
std:: env:: set_var ( OTEL_EXPORTER_OTLP_TIMEOUT , "bad_timeout" ) ;
171
165
172
166
let mut exporter_builder = new_exporter ( ) . tonic ( ) . with_env ( ) ;
167
+ assert_eq ! ( exporter_builder. exporter_config. endpoint, expected_endpoint) ;
168
+
169
+ exporter_builder = new_exporter ( ) . tonic ( ) . with_env ( ) ;
173
170
assert_eq ! (
174
171
exporter_builder. exporter_config. timeout,
175
172
std:: time:: Duration :: from_secs( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT )
@@ -187,31 +184,5 @@ mod tests {
187
184
std:: env:: remove_var ( OTEL_EXPORTER_OTLP_TIMEOUT ) ;
188
185
assert ! ( std:: env:: var( OTEL_EXPORTER_OTLP_ENDPOINT ) . is_err( ) ) ;
189
186
assert ! ( std:: env:: var( OTEL_EXPORTER_OTLP_TIMEOUT ) . is_err( ) ) ;
190
-
191
- // test from traces env var
192
- std:: env:: set_var (
193
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,
194
- "https://otlp_traces_endpoint:4317" ,
195
- ) ;
196
- std:: env:: set_var ( OTEL_EXPORTER_OTLP_TRACES_TIMEOUT , "bad_timeout" ) ;
197
-
198
- let mut exporter_builder = new_exporter ( ) . tonic ( ) . with_env ( ) ;
199
- assert_eq ! (
200
- exporter_builder. exporter_config. timeout,
201
- std:: time:: Duration :: from_secs( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT )
202
- ) ;
203
-
204
- std:: env:: set_var ( OTEL_EXPORTER_OTLP_TRACES_TIMEOUT , "60" ) ;
205
-
206
- exporter_builder = new_exporter ( ) . tonic ( ) . with_env ( ) ;
207
- assert_eq ! (
208
- exporter_builder. exporter_config. timeout,
209
- std:: time:: Duration :: from_secs( 60 )
210
- ) ;
211
-
212
- std:: env:: remove_var ( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ) ;
213
- std:: env:: remove_var ( OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ) ;
214
- assert ! ( std:: env:: var( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ) . is_err( ) ) ;
215
- assert ! ( std:: env:: var( OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ) . is_err( ) ) ;
216
187
}
217
188
}
0 commit comments