@@ -6,8 +6,7 @@ use http::Uri;
66use model:: endpoint:: Endpoint ;
77use opentelemetry_http:: HttpClient ;
88use opentelemetry_sdk:: error:: OTelSdkResult ;
9- use opentelemetry_sdk:: trace:: TraceError ;
10- use opentelemetry_sdk:: { trace, ExportError } ;
9+ use opentelemetry_sdk:: trace;
1110use std:: net:: { AddrParseError , SocketAddr } ;
1211use std:: sync:: Arc ;
1312
@@ -75,7 +74,7 @@ impl ZipkinExporterBuilder {
7574 /// Creates a new [ZipkinExporter] from this configuration.
7675 ///
7776 /// 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 > {
7978 let endpoint = Endpoint :: new ( self . service_addr ) ;
8079
8180 if let Some ( client) = self . client {
@@ -84,15 +83,19 @@ impl ZipkinExporterBuilder {
8483 client,
8584 self . collector_endpoint
8685 . parse ( )
87- . map_err :: < Error , _ > ( Into :: into ) ?,
86+ . map_err ( ExporterBuildError :: InvalidUri ) ?,
8887 ) ;
8988 Ok ( exporter)
9089 } else {
91- Err ( Error :: NoHttpClient . into ( ) )
90+ Err ( ExporterBuildError :: NoHttpClient )
9291 }
9392 }
9493
9594 /// 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`.
9699 pub fn with_http_client < T : HttpClient + ' static > ( mut self , client : T ) -> Self {
97100 self . client = Some ( Arc :: new ( client) ) ;
98101 self
@@ -105,6 +108,9 @@ impl ZipkinExporterBuilder {
105108 }
106109
107110 /// 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`.
108114 pub fn with_collector_endpoint < T : Into < String > > ( mut self , endpoint : T ) -> Self {
109115 self . collector_endpoint = endpoint. into ( ) ;
110116 self
@@ -134,30 +140,42 @@ impl trace::SpanExporter for ZipkinExporter {
134140/// Wrap type for errors from opentelemetry zipkin
135141#[ derive( thiserror:: Error , Debug ) ]
136142#[ non_exhaustive]
137- pub enum Error {
143+ pub enum ExporterBuildError {
138144 /// No http client implementation found. User should provide one or enable features.
139145 #[ error( "http client must be set, users can enable reqwest feature to use http client implementation within create" ) ]
140146 NoHttpClient ,
141147
142- /// Http requests failed
143- #[ error( "http request failed with {0}" ) ]
144- RequestFailed ( #[ from] http:: Error ) ,
145-
146148 /// The uri provided is invalid
147149 #[ error( "invalid uri" ) ]
148150 InvalidUri ( #[ from] http:: uri:: InvalidUri ) ,
149151
150152 /// The IP/socket address provided is invalid
151153 #[ error( "invalid address" ) ]
152154 InvalidAddress ( #[ from] AddrParseError ) ,
153-
154- /// Other errors
155- #[ error( "export error: {0}" ) ]
156- Other ( String ) ,
157155}
158156
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+ } ) ;
162180 }
163181}
0 commit comments