From 74dc01beada11ccd26b31cdeeedba95d4ab02160 Mon Sep 17 00:00:00 2001 From: Orion Bloomfield Date: Fri, 31 Jan 2025 18:06:36 -0800 Subject: [PATCH] add CLI flag to disable span trace logging --- README.md | 5 +++++ docs/source/en/cli_arguments.md | 5 +++++ router/src/logging.rs | 14 ++++++++++---- router/src/main.rs | 5 +++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5c7b9680..2724baf2 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,11 @@ Options: [env: JSON_OUTPUT=] + --disable-spans + Disables the span logging trace + + [env: DISABLE_SPANS=] + --otlp-endpoint The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317` diff --git a/docs/source/en/cli_arguments.md b/docs/source/en/cli_arguments.md index e25e60b7..96f63d9c 100644 --- a/docs/source/en/cli_arguments.md +++ b/docs/source/en/cli_arguments.md @@ -182,6 +182,11 @@ Options: [env: JSON_OUTPUT=] + --disable-spans + Disables the span logging trace + + [env: DISABLE_SPANS=] + --otlp-endpoint The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317` diff --git a/router/src/logging.rs b/router/src/logging.rs index 7a8fe810..978988a1 100644 --- a/router/src/logging.rs +++ b/router/src/logging.rs @@ -14,6 +14,7 @@ pub fn init_logging( otlp_endpoint: Option<&String>, otlp_service_name: String, json_output: bool, + disable_spans: bool, ) -> bool { let mut layers = Vec::new(); @@ -22,10 +23,15 @@ pub fn init_logging( .with_file(true) .with_line_number(true); - let fmt_layer = match json_output { - true => fmt_layer.json().flatten_event(true).boxed(), - false => fmt_layer.boxed(), - }; + let fmt_layer = match json_output { + true => fmt_layer + .json() + .flatten_event(true) + .with_current_span(!disable_spans) + .with_span_list(!disable_spans) + .boxed(), + false => fmt_layer.boxed(), + }; layers.push(fmt_layer); // OpenTelemetry tracing layer diff --git a/router/src/main.rs b/router/src/main.rs index 67fb76c7..77658fb5 100644 --- a/router/src/main.rs +++ b/router/src/main.rs @@ -145,6 +145,10 @@ struct Args { #[clap(long, env)] json_output: bool, + // Whether or not to include the log trace through spans + #[clap(long, env)] + disable_spans: bool, + /// The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. /// e.g. `http://localhost:4317` #[clap(long, env)] @@ -170,6 +174,7 @@ async fn main() -> Result<()> { args.otlp_endpoint.as_ref(), args.otlp_service_name.clone(), args.json_output, + args.disable_spans, ); tracing::info!("{args:?}");