Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CLI flag disable-spans to toggle span trace logging #481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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