Skip to content

Commit 6e472d4

Browse files
stdout if either endpoint is set to stdout
1 parent ce280fd commit 6e472d4

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/telemetry.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ const OTEL_EXPORTER_OTLP_PROTOCOL: &str = "OTEL_EXPORTER_OTLP_PROTOCOL";
5353
/// Returns \`None\` when \`OTEL_EXPORTER_OTLP_ENDPOINT\` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is not set (OTEL disabled).
5454
/// The caller must call \`provider.shutdown()\` before process exit.
5555
pub fn init_tracing(service: &'static str) -> Option<SdkTracerProvider> {
56-
let endpoint = std::env::var(OTEL_EXPORTER_OTLP_ENDPOINT)
57-
.or_else(|_| std::env::var(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT))
58-
.ok()?;
56+
let endpoint = std::env::var(OTEL_EXPORTER_OTLP_ENDPOINT).ok();
57+
let traces_endpoint = std::env::var(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT).ok();
58+
if endpoint.is_none() && traces_endpoint.is_none() {
59+
return None;
60+
}
5961

6062
// Endpoint sentinel: route spans to stdout, skip OTLP exporter entirely.
61-
let use_stdout = endpoint.eq_ignore_ascii_case("stdout");
63+
// Either env var set to "stdout" (case-insensitive) triggers stdout mode.
64+
let is_stdout_sentinel = |v: &Option<String>| {
65+
v.as_deref()
66+
.is_some_and(|s| s.eq_ignore_ascii_case("stdout"))
67+
};
68+
let use_stdout = is_stdout_sentinel(&endpoint) || is_stdout_sentinel(&traces_endpoint);
6269

6370
let protocol =
6471
std::env::var(OTEL_EXPORTER_OTLP_PROTOCOL).unwrap_or_else(|_| "http/json".to_string());

0 commit comments

Comments
 (0)