Skip to content

Commit

Permalink
fix: Fix env endpoint use in telemetry agent (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
karolisg committed Jul 29, 2023
1 parent 6962621 commit 8975aa3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions opentelemetry-jaeger/src/exporter/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const ENV_AGENT_HOST: &str = "OTEL_EXPORTER_JAEGER_AGENT_HOST";
/// e.g. 6832
const ENV_AGENT_PORT: &str = "OTEL_EXPORTER_JAEGER_AGENT_PORT";

/// Default agent endpoint if none is provided
const DEFAULT_AGENT_ENDPOINT: &str = "127.0.0.1:6831";
/// Default agent host if none is provided
const DEFAULT_AGENT_ENDPOINT_HOST: &str = "127.0.0.1";

/// Default agent port if none is provided
const DEFAULT_AGENT_ENDPOINT_PORT: &str = "6831";

/// AgentPipeline config and build a exporter targeting a jaeger agent using UDP as transport layer protocol.
///
Expand Down Expand Up @@ -84,16 +87,26 @@ impl Default for AgentPipeline {
transformation_config: Default::default(),
trace_config: Default::default(),
batch_config: Some(Default::default()),
agent_endpoint: Ok(vec![DEFAULT_AGENT_ENDPOINT.parse().unwrap()]),
agent_endpoint: Ok(vec![format!(
"{DEFAULT_AGENT_ENDPOINT_HOST}:{DEFAULT_AGENT_ENDPOINT_PORT}"
)
.parse()
.unwrap()]),
max_packet_size: UDP_PACKET_MAX_LENGTH,
auto_split_batch: false,
};

if let (Ok(host), Ok(port)) = (env::var(ENV_AGENT_HOST), env::var(ENV_AGENT_PORT)) {
pipeline = pipeline.with_endpoint(format!("{}:{}", host.trim(), port.trim()));
} else if let Ok(port) = env::var(ENV_AGENT_PORT) {
pipeline = pipeline.with_endpoint(format!("127.0.0.1:{}", port.trim()))
let endpoint = match (env::var(ENV_AGENT_HOST), env::var(ENV_AGENT_PORT)) {
(Ok(host), Ok(port)) => Some(format!("{}:{}", host.trim(), port.trim())),
(Ok(host), _) => Some(format!("{}:{DEFAULT_AGENT_ENDPOINT_PORT}", host.trim())),
(_, Ok(port)) => Some(format!("{DEFAULT_AGENT_ENDPOINT_HOST}:{}", port.trim())),
(_, _) => None,
};

if let Some(endpoint) = endpoint {
pipeline = pipeline.with_endpoint(endpoint);
}

pipeline
}
}
Expand Down

0 comments on commit 8975aa3

Please sign in to comment.