forked from open-telemetry/opentelemetry-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opentelemetry-zipkin: Add Environment Variables
As described in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md * Add support for: ** OTEL_EXPORTER_ZIPKIN_ENDPOINT ** OTEL_EXPORTER_ZIPKIN_TIMEOUT * Update Default to use Closes open-telemetry#534 Signed-off-by: Harold Dost <h.dost@criteo.com>
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::ZipkinPipelineBuilder; | ||
use log::warn; | ||
use std::env; | ||
use std::time::Duration; | ||
|
||
/// HTTP endpoint for Zipkin collector. | ||
/// e.g. "http://localhost:9411/api/v2/spans" | ||
#[cfg(any( | ||
feature = "reqwest-client", | ||
feature = "surf-client", | ||
feature = "reqwest-blocking-client" | ||
))] | ||
const ENV_ENDPOINT: &str = "OTEL_EXPORTER_ZIPKIN_ENDPOINT"; | ||
|
||
/// Maximum time the Zipkin exporter will wait for each batch export | ||
#[cfg(any( | ||
feature = "reqwest-client", | ||
feature = "surf-client", | ||
feature = "reqwest-blocking-client" | ||
))] | ||
const ENV_TIMEOUT: &str = "OTEL_EXPORTER_ZIPKIN_TIMEOUT"; | ||
|
||
/// Assign builder attributes from env | ||
pub(crate) fn assign_attrs(mut builder: ZipkinPipelineBuilder) -> ZipkinPipelineBuilder { | ||
#[cfg(any( | ||
feature = "reqwest-client", | ||
feature = "surf-client", | ||
feature = "reqwest-blocking-client" | ||
))] | ||
{ | ||
if let Some(endpoint) = env::var(ENV_ENDPOINT).ok().filter(|var| !var.is_empty()) { | ||
builder = builder.with_collector_endpoint(endpoint); | ||
} | ||
} | ||
|
||
#[cfg(any( | ||
feature = "reqwest-client", | ||
feature = "surf-client", | ||
feature = "reqwest-blocking-client" | ||
))] | ||
{ | ||
if let Some(timeout) = env::var(ENV_TIMEOUT).ok().filter(|var| !var.is_empty()) { | ||
let timeout = match timeout.parse() { | ||
Ok(timeout) => Duration::from_millis(timeout), | ||
Err(e) => { | ||
warn!("{} malformed defaulting to 10000: {}", ENV_TIMEOUT, e); | ||
Duration::from_millis(10_000) | ||
} | ||
}; | ||
|
||
#[cfg(feature = "reqwest-blocking-client")] | ||
let client = reqwest::blocking::Client::builder() | ||
.timeout(timeout) | ||
.build() | ||
.unwrap(); | ||
#[cfg(all( | ||
not(feature = "reqwest-blocking-client"), | ||
not(feature = "surf-client"), | ||
feature = "reqwest-client" | ||
))] | ||
let client = reqwest::Client::builder().timeout(timeout).build().unwrap(); | ||
#[cfg(all( | ||
not(feature = "reqwest-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
feature = "surf-client" | ||
))] | ||
let client: surf::Client = surf::Config::new().set_timeout(Some(timeout)).into(); | ||
|
||
builder = builder.with_http_client(client); | ||
} | ||
} | ||
|
||
builder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters