Skip to content

Commit

Permalink
add CLI flag to disable span trace logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Orion Bloomfield committed Feb 1, 2025
1 parent f0e491a commit 74dc01b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ Options:
[env: JSON_OUTPUT=]
--disable-spans
Disables the span logging trace
[env: DISABLE_SPANS=]
--otlp-endpoint <OTLP_ENDPOINT>
The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317`
Expand Down
5 changes: 5 additions & 0 deletions docs/source/en/cli_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ Options:
[env: JSON_OUTPUT=]
--disable-spans
Disables the span logging trace
[env: DISABLE_SPANS=]
--otlp-endpoint <OTLP_ENDPOINT>
The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317`
Expand Down
14 changes: 10 additions & 4 deletions router/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions router/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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:?}");
Expand Down

0 comments on commit 74dc01b

Please sign in to comment.