@@ -6,8 +6,7 @@ use http::Uri;
6
6
use model:: endpoint:: Endpoint ;
7
7
use opentelemetry_http:: HttpClient ;
8
8
use opentelemetry_sdk:: error:: OTelSdkResult ;
9
- use opentelemetry_sdk:: trace:: TraceError ;
10
- use opentelemetry_sdk:: { trace, ExportError } ;
9
+ use opentelemetry_sdk:: trace;
11
10
use std:: net:: { AddrParseError , SocketAddr } ;
12
11
use std:: sync:: Arc ;
13
12
@@ -75,7 +74,7 @@ impl ZipkinExporterBuilder {
75
74
/// Creates a new [ZipkinExporter] from this configuration.
76
75
///
77
76
/// Returns error if the endpoint is not valid or if no http client is provided.
78
- pub fn build ( self ) -> Result < ZipkinExporter , TraceError > {
77
+ pub fn build ( self ) -> Result < ZipkinExporter , ExporterBuildError > {
79
78
let endpoint = Endpoint :: new ( self . service_addr ) ;
80
79
81
80
if let Some ( client) = self . client {
@@ -84,15 +83,19 @@ impl ZipkinExporterBuilder {
84
83
client,
85
84
self . collector_endpoint
86
85
. parse ( )
87
- . map_err :: < Error , _ > ( Into :: into ) ?,
86
+ . map_err ( ExporterBuildError :: InvalidUri ) ?,
88
87
) ;
89
88
Ok ( exporter)
90
89
} else {
91
- Err ( Error :: NoHttpClient . into ( ) )
90
+ Err ( ExporterBuildError :: NoHttpClient )
92
91
}
93
92
}
94
93
95
94
/// Assign client implementation
95
+ ///
96
+ /// When using this method, the export timeout will depend on the provided
97
+ /// client implementation and may not respect the timeout set via the
98
+ /// environment variable `OTEL_EXPORTER_ZIPKIN_TIMEOUT`.
96
99
pub fn with_http_client < T : HttpClient + ' static > ( mut self , client : T ) -> Self {
97
100
self . client = Some ( Arc :: new ( client) ) ;
98
101
self
@@ -105,6 +108,9 @@ impl ZipkinExporterBuilder {
105
108
}
106
109
107
110
/// Assign the Zipkin collector endpoint
111
+ ///
112
+ /// Note: Programmatically setting this will override any value
113
+ /// set via the environment variable `OTEL_EXPORTER_ZIPKIN_ENDPOINT`.
108
114
pub fn with_collector_endpoint < T : Into < String > > ( mut self , endpoint : T ) -> Self {
109
115
self . collector_endpoint = endpoint. into ( ) ;
110
116
self
@@ -134,30 +140,42 @@ impl trace::SpanExporter for ZipkinExporter {
134
140
/// Wrap type for errors from opentelemetry zipkin
135
141
#[ derive( thiserror:: Error , Debug ) ]
136
142
#[ non_exhaustive]
137
- pub enum Error {
143
+ pub enum ExporterBuildError {
138
144
/// No http client implementation found. User should provide one or enable features.
139
145
#[ error( "http client must be set, users can enable reqwest feature to use http client implementation within create" ) ]
140
146
NoHttpClient ,
141
147
142
- /// Http requests failed
143
- #[ error( "http request failed with {0}" ) ]
144
- RequestFailed ( #[ from] http:: Error ) ,
145
-
146
148
/// The uri provided is invalid
147
149
#[ error( "invalid uri" ) ]
148
150
InvalidUri ( #[ from] http:: uri:: InvalidUri ) ,
149
151
150
152
/// The IP/socket address provided is invalid
151
153
#[ error( "invalid address" ) ]
152
154
InvalidAddress ( #[ from] AddrParseError ) ,
153
-
154
- /// Other errors
155
- #[ error( "export error: {0}" ) ]
156
- Other ( String ) ,
157
155
}
158
156
159
- impl ExportError for Error {
160
- fn exporter_name ( & self ) -> & ' static str {
161
- "zipkin"
157
+ #[ cfg( test) ]
158
+ mod tests {
159
+ use super :: * ;
160
+ use crate :: exporter:: env:: ENV_ENDPOINT ;
161
+
162
+ #[ test]
163
+ fn test_priority_of_code_based_config_over_envs_for_endpoint ( ) {
164
+ temp_env:: with_vars ( [ ( ENV_ENDPOINT , Some ( "http://127.0.0.1:1234" ) ) ] , || {
165
+ let builder =
166
+ ZipkinExporterBuilder :: default ( ) . with_collector_endpoint ( "http://127.0.0.1:2345" ) ;
167
+ assert_eq ! ( builder. collector_endpoint, "http://127.0.0.1:2345" ) ;
168
+ } ) ;
169
+ }
170
+
171
+ #[ test]
172
+ fn test_use_default_when_others_missing_for_endpoint ( ) {
173
+ temp_env:: with_vars ( [ ( ENV_ENDPOINT , None :: < & str > ) ] , || {
174
+ let builder = ZipkinExporterBuilder :: default ( ) ;
175
+ assert_eq ! (
176
+ builder. collector_endpoint,
177
+ "http://127.0.0.1:9411/api/v2/spans"
178
+ ) ;
179
+ } ) ;
162
180
}
163
181
}
0 commit comments