logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::PipelineBuilder;
use std::env;

/// The hostname for the Jaeger agent.
/// e.g. "localhost"
const ENV_AGENT_HOST: &str = "OTEL_EXPORTER_JAEGER_AGENT_HOST";

/// The port for the Jaeger agent.
/// e.g. 6832
const ENV_AGENT_PORT: &str = "OTEL_EXPORTER_JAEGER_AGENT_PORT";

/// HTTP endpoint for Jaeger collector.
/// e.g. "http://localhost:14250"
#[cfg(feature = "collector_client")]
const ENV_ENDPOINT: &str = "OTEL_EXPORTER_JAEGER_ENDPOINT";

/// Username to send as part of "Basic" authentication to the collector endpoint.
#[cfg(feature = "collector_client")]
const ENV_USER: &str = "OTEL_EXPORTER_JAEGER_USER";

/// Password to send as part of "Basic" authentication to the collector endpoint.
#[cfg(feature = "collector_client")]
const ENV_PASSWORD: &str = "OTEL_EXPORTER_JAEGER_PASSWORD";

/// Assign builder attributes from env
pub(crate) fn assign_attrs(mut builder: PipelineBuilder) -> PipelineBuilder {
    if let (Ok(host), Ok(port)) = (env::var(ENV_AGENT_HOST), env::var(ENV_AGENT_PORT)) {
        builder = builder.with_agent_endpoint(format!("{}:{}", host.trim(), port.trim()));
    }

    #[cfg(feature = "collector_client")]
    {
        if let Some(endpoint) = env::var(ENV_ENDPOINT).ok().filter(|var| !var.is_empty()) {
            builder = builder.with_collector_endpoint(endpoint);
        }
    }

    #[cfg(feature = "collector_client")]
    {
        if let Some(user) = env::var(ENV_USER).ok().filter(|var| !var.is_empty()) {
            builder = builder.with_collector_username(user);
        }
    }

    #[cfg(feature = "collector_client")]
    {
        if let Some(password) = env::var(ENV_PASSWORD).ok().filter(|var| !var.is_empty()) {
            builder = builder.with_collector_password(password);
        }
    }

    builder
}