Skip to content

Commit 33b4dfe

Browse files
committed
validate code-based config is preferred over env vars in ZipkinExporterBuilder
1 parent 31b494b commit 33b4dfe

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

opentelemetry-zipkin/src/exporter/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const DEFAULT_COLLECTOR_ENDPOINT: &str = "http://127.0.0.1:9411/api/v2/spans";
66

77
/// HTTP endpoint for Zipkin collector.
88
/// e.g. "http://localhost:9411/api/v2/spans"
9-
const ENV_ENDPOINT: &str = "OTEL_EXPORTER_ZIPKIN_ENDPOINT";
9+
pub(crate) const ENV_ENDPOINT: &str = "OTEL_EXPORTER_ZIPKIN_ENDPOINT";
1010

1111
/// Maximum time the Zipkin exporter will wait for each batch export
1212
const ENV_TIMEOUT: &str = "OTEL_EXPORTER_ZIPKIN_TIMEOUT";

opentelemetry-zipkin/src/exporter/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ impl ZipkinExporterBuilder {
9393
}
9494

9595
/// Assign client implementation
96+
///
97+
/// Note: Programmatically setting the timeout will override any value
98+
/// set via the 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
@@ -161,3 +167,29 @@ impl ExportError for Error {
161167
"zipkin"
162168
}
163169
}
170+
171+
#[cfg(test)]
172+
mod tests {
173+
use super::*;
174+
use crate::exporter::env::ENV_ENDPOINT;
175+
176+
#[test]
177+
fn test_priority_of_code_based_config_over_envs_for_endpoint() {
178+
temp_env::with_vars([(ENV_ENDPOINT, Some("http://127.0.0.1:1234"))], || {
179+
let builder =
180+
ZipkinExporterBuilder::default().with_collector_endpoint("http://127.0.0.1:2345");
181+
assert_eq!(builder.collector_endpoint, "http://127.0.0.1:2345");
182+
});
183+
}
184+
185+
#[test]
186+
fn test_use_default_when_others_missing_for_endpoint() {
187+
temp_env::with_vars([(ENV_ENDPOINT, None::<&str>)], || {
188+
let builder = ZipkinExporterBuilder::default();
189+
assert_eq!(
190+
builder.collector_endpoint,
191+
"http://127.0.0.1:9411/api/v2/spans"
192+
);
193+
});
194+
}
195+
}

0 commit comments

Comments
 (0)