Skip to content

Commit c3d8b8b

Browse files
committed
Use stackable-tracing
1 parent aa30f9c commit c3d8b8b

4 files changed

Lines changed: 49 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cert-tools/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ publish = false
1010

1111
[dependencies]
1212
stackable-secret-operator-utils = { path = "../utils" }
13+
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", features = ["clap"], tag = "stackable-telemetry-0.6.1" }
1314

1415
clap = { workspace = true, features = ["derive"] }
1516
hex.workspace = true

rust/cert-tools/src/cli_args.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
use std::{fs, path::PathBuf};
22

3-
use clap::Parser;
3+
use clap::{Parser, Subcommand};
44
use openssl::x509::X509;
55
use snafu::{ResultExt, ensure_whatever};
6+
use stackable_telemetry::tracing::TelemetryOptions;
67

78
use crate::parsers::{parse_pem_contents, parse_pkcs12_file_workaround};
89

910
#[derive(Parser, Debug)]
1011
#[command(version, about)]
11-
pub enum Cli {
12+
pub struct Cli {
13+
#[command(subcommand)]
14+
pub command: CliCommand,
15+
16+
#[command(flatten, next_help_heading = "Tracing options")]
17+
pub telemetry: TelemetryOptions,
18+
}
19+
20+
#[derive(Subcommand, Debug)]
21+
pub enum CliCommand {
1222
/// Generate PKCS12 truststore files from PEM or PKCS12 files
1323
GeneratePkcs12Truststore(GeneratePkcs12),
1424
}

rust/cert-tools/src/main.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,28 @@ use std::{collections::HashMap, fs};
22

33
use cert_ext::CertExt;
44
use clap::Parser;
5-
use cli_args::{Cli, GeneratePkcs12};
5+
use cli_args::{Cli, CliCommand, GeneratePkcs12};
66
use openssl::x509::X509;
77
use snafu::{ResultExt, ensure_whatever};
88
use stackable_secret_operator_utils::pkcs12::pkcs12_truststore;
9-
use tracing::{info, level_filters::LevelFilter, warn};
9+
use stackable_telemetry::Tracing;
10+
use tracing::{info, warn};
1011

1112
mod cert_ext;
1213
mod cli_args;
1314
mod parsers;
1415

1516
#[snafu::report]
1617
pub fn main() -> Result<(), snafu::Whatever> {
17-
let filter = tracing_subscriber::EnvFilter::builder()
18-
.with_default_directive(LevelFilter::INFO.into())
19-
.from_env()
20-
.whatever_context("failed to create tracing subscriber EnvFilter")?;
21-
tracing_subscriber::fmt()
22-
// Short running tool does not need any complex output
23-
.with_target(false)
24-
.without_time()
25-
.with_env_filter(filter)
26-
.init();
27-
2818
let cli = Cli::parse();
2919

30-
match cli {
31-
Cli::GeneratePkcs12Truststore(cli_args) => generate_pkcs12_truststore(cli_args)?,
20+
// Use `CONSOLE_LOG_LEVEL` to modify the console log level
21+
let _tracing_guard = Tracing::pre_configured("cert-tools", cli.telemetry)
22+
.init()
23+
.whatever_context("failed to initialize tracing")?;
24+
25+
match cli.command {
26+
CliCommand::GeneratePkcs12Truststore(cli_args) => generate_pkcs12_truststore(cli_args)?,
3227
}
3328

3429
Ok(())

0 commit comments

Comments
 (0)