Skip to content

Commit f1634ba

Browse files
obloomfieldOrion Bloomfield
and
Orion Bloomfield
authored
add CLI flag disable-spans to toggle span trace logging (#481)
Co-authored-by: Orion Bloomfield <[email protected]>
1 parent 260965d commit f1634ba

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
@@ -290,6 +290,11 @@ Options:
290290
291291
[env: JSON_OUTPUT=]
292292
293+
--disable-spans
294+
Disables the span logging trace
295+
296+
[env: DISABLE_SPANS=]
297+
293298
--otlp-endpoint <OTLP_ENDPOINT>
294299
The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC. e.g. `http://localhost:4317`
295300

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
@@ -150,6 +150,10 @@ struct Args {
150150
#[clap(long, env)]
151151
json_output: bool,
152152

153+
// Whether or not to include the log trace through spans
154+
#[clap(long, env)]
155+
disable_spans: bool,
156+
153157
/// The grpc endpoint for opentelemetry. Telemetry is sent to this endpoint as OTLP over gRPC.
154158
/// e.g. `http://localhost:4317`
155159
#[clap(long, env)]
@@ -175,6 +179,7 @@ async fn main() -> Result<()> {
175179
args.otlp_endpoint.as_ref(),
176180
args.otlp_service_name.clone(),
177181
args.json_output,
182+
args.disable_spans,
178183
);
179184

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

0 commit comments

Comments
 (0)