Skip to content

Commit 74dc01b

Browse files
author
Orion Bloomfield
committed
add CLI flag to disable span trace logging
1 parent f0e491a commit 74dc01b

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ Options:
287287
288288
[env: JSON_OUTPUT=]
289289
290+
--disable-spans
291+
Disables the span logging trace
292+
293+
[env: DISABLE_SPANS=]
294+
290295
--otlp-endpoint <OTLP_ENDPOINT>
291296
The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317`
292297

docs/source/en/cli_arguments.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ Options:
182182
183183
[env: JSON_OUTPUT=]
184184
185+
--disable-spans
186+
Disables the span logging trace
187+
188+
[env: DISABLE_SPANS=]
189+
185190
--otlp-endpoint <OTLP_ENDPOINT>
186191
The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317`
187192

router/src/logging.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn init_logging(
1414
otlp_endpoint: Option<&String>,
1515
otlp_service_name: String,
1616
json_output: bool,
17+
disable_spans: bool,
1718
) -> bool {
1819
let mut layers = Vec::new();
1920

@@ -22,10 +23,15 @@ pub fn init_logging(
2223
.with_file(true)
2324
.with_line_number(true);
2425

25-
let fmt_layer = match json_output {
26-
true => fmt_layer.json().flatten_event(true).boxed(),
27-
false => fmt_layer.boxed(),
28-
};
26+
let fmt_layer = match json_output {
27+
true => fmt_layer
28+
.json()
29+
.flatten_event(true)
30+
.with_current_span(!disable_spans)
31+
.with_span_list(!disable_spans)
32+
.boxed(),
33+
false => fmt_layer.boxed(),
34+
};
2935
layers.push(fmt_layer);
3036

3137
// OpenTelemetry tracing layer

router/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ struct Args {
145145
#[clap(long, env)]
146146
json_output: bool,
147147

148+
// Whether or not to include the log trace through spans
149+
#[clap(long, env)]
150+
disable_spans: bool,
151+
148152
/// The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC.
149153
/// e.g. `http://localhost:4317`
150154
#[clap(long, env)]
@@ -170,6 +174,7 @@ async fn main() -> Result<()> {
170174
args.otlp_endpoint.as_ref(),
171175
args.otlp_service_name.clone(),
172176
args.json_output,
177+
args.disable_spans,
173178
);
174179

175180
tracing::info!("{args:?}");

0 commit comments

Comments
 (0)