Skip to content

Commit e041dcb

Browse files
committed
refactor: clarify why endpoints read from environment variables are not used
1 parent 2a60f21 commit e041dcb

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

init-tracing-opentelemetry/src/otlp/logs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ pub fn init_loggerprovider<F>(
1616
where
1717
F: FnOnce(LoggerProviderBuilder) -> LoggerProviderBuilder,
1818
{
19-
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
20-
let protocol = infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref());
19+
let protocol = {
20+
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
21+
infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref())
22+
};
2123

24+
// builders used the environment variables to determine the endpoint (but not to setup the protocol)
2225
let exporter: Option<LogExporter> = match protocol.as_deref() {
2326
Some("http/protobuf") => Some(LogExporter::builder().with_http().build()?),
2427
#[cfg(feature = "tls")]

init-tracing-opentelemetry/src/otlp/metrics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pub fn init_meterprovider<F>(
2121
where
2222
F: FnOnce(MeterProviderBuilder) -> MeterProviderBuilder,
2323
{
24-
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
25-
let protocol = infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref());
24+
let protocol = {
25+
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
26+
infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref())
27+
};
2628
let timeout = env::var("OTEL_EXPORTER_OTLP_METRICS_TIMEOUT")
2729
.ok()
2830
.and_then(|var| var.parse::<u64>().ok())
@@ -43,6 +45,7 @@ where
4345
.and_then(|var| var.parse::<u64>().ok())
4446
.map_or(Duration::from_secs(60), Duration::from_millis);
4547

48+
// builders used the environment variables to determine the endpoint (but not to setup the protocol)
4649
let exporter = match protocol.as_deref() {
4750
Some("http/protobuf") => Some(
4851
MetricExporter::builder()

init-tracing-opentelemetry/src/otlp/traces.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ where
1818
F: FnOnce(TracerProviderBuilder) -> TracerProviderBuilder,
1919
{
2020
debug_env();
21-
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
22-
let protocol = infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref());
21+
let protocol = {
22+
let (maybe_protocol, maybe_endpoint) = read_protocol_and_endpoint_from_env();
23+
infer_protocol(maybe_protocol.as_deref(), maybe_endpoint.as_deref())
24+
};
2325

26+
// builders used the environment variables to determine the endpoint (but not to setup the protocol)
2427
let exporter: Option<SpanExporter> = match protocol.as_deref() {
2528
Some("http/protobuf") => Some(SpanExporter::builder().with_http().build()?),
2629
#[cfg(feature = "tls")]

0 commit comments

Comments
 (0)