diff --git a/Cargo.lock b/Cargo.lock index e1946e5..dc6656a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,6 +172,22 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "crossbeam-channel" version = "0.5.4" @@ -714,6 +730,12 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "opentelemetry" version = "0.17.0" @@ -1062,6 +1084,18 @@ dependencies = [ "webpki 0.22.0", ] +[[package]] +name = "rustls-native-certs" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" +dependencies = [ + "openssl-probe", + "rustls 0.19.1", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.0" @@ -1086,6 +1120,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1112,6 +1156,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.144" @@ -1440,6 +1507,7 @@ dependencies = [ "pin-project", "prost", "prost-derive", + "rustls-native-certs", "tokio", "tokio-rustls 0.22.0", "tokio-stream", diff --git a/Cargo.toml b/Cargo.toml index 94f5f3d..956c314 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ lazy_static = "1.4" nix = "0.25.0" once_cell = "1.13" opentelemetry = { version = "0.17", features = ["rt-tokio"] } -opentelemetry-otlp = { version = "0.10", features = ["tonic", "tls"] } +opentelemetry-otlp = { version = "0.10", features = ["tonic", "tls-roots"] } reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls", "json", "blocking"] } rustls = "0.20" serde = { version = "1.0", features = ["derive", "rc"] } diff --git a/src/commands/apply.rs b/src/commands/apply.rs index 1473b12..cb0c6e5 100644 --- a/src/commands/apply.rs +++ b/src/commands/apply.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; use clap::Arg; -use tracing::{info_span, instrument}; use opentelemetry::trace::SpanKind; +use tracing::{info_span, instrument}; use super::*; @@ -30,13 +30,17 @@ impl Command for ApplyCommand { impl CommandRunnable for ApplyCommand { #[instrument(name = "command.apply", fields(otel.kind = %SpanKind::Client), skip(self, matches), err)] - fn run( - &self, - matches: &clap::ArgMatches, - ) -> Result { - let config_dir: PathBuf = matches.value_of("config") - .map(|p| p.into()) - .ok_or_else(|| errors::user("No configuration directory provided.", "Provide the --config directory when running this command."))?; + fn run(&self, matches: &clap::ArgMatches) -> Result { + let config_dir: PathBuf = + matches + .value_of("config") + .map(|p| p.into()) + .ok_or_else(|| { + errors::user( + "No configuration directory provided.", + "Provide the --config directory when running this command.", + ) + })?; let mut output = crate::core::output::output(); @@ -44,7 +48,7 @@ impl CommandRunnable for ApplyCommand { for (key, val) in config.iter() { writeln!(output, " = config {}={}", key, val)?; } - + let secrets = crate::core::config::load_all_config(&config_dir.join("secrets"))?; for (key, _val) in secrets.iter() { writeln!(output, " = secret {}=******", key)?; @@ -73,8 +77,17 @@ impl CommandRunnable for ApplyCommand { let root_path = PathBuf::from("/"); let files = package.get_files()?; for file in files { - let target_path = package.files.get(&file.group).map(|f| f.as_path()).unwrap_or(&root_path); - writeln!(output, " + {} '{}'", if file.is_template { "template" } else { "file" }, target_path.join(&file.relative_path).display())?; + let target_path = package + .files + .get(&file.group) + .map(|f| f.as_path()) + .unwrap_or(&root_path); + writeln!( + output, + " + {} '{}'", + if file.is_template { "template" } else { "file" }, + target_path.join(&file.relative_path).display() + )?; file.apply(target_path, &config, &secrets)?; } @@ -101,13 +114,17 @@ mod tests { fn run() { let _guard = test_tracing(); let temp = tempfile::tempdir().unwrap(); - - let cmd = ApplyCommand{}; - - let args = cmd.app().get_matches_from(vec!["apply", "--config", get_test_data().to_str().unwrap()]); - + + let cmd = ApplyCommand {}; + + let args = cmd.app().get_matches_from(vec![ + "apply", + "--config", + get_test_data().to_str().unwrap(), + ]); + let output = crate::core::output::mock(); - + let temp_path = temp.path().to_owned(); crate::core::file::File::apply.mock_safe(move |f, target, config, secrets| { let target = Box::leak(Box::new(temp_path.join(target.strip_prefix("/").unwrap()))); diff --git a/src/commands/plan.rs b/src/commands/plan.rs index 6644fe4..37d8b6c 100644 --- a/src/commands/plan.rs +++ b/src/commands/plan.rs @@ -1,8 +1,8 @@ -use std::path::PathBuf; +use crate::errors; use clap::Arg; -use tracing::{info_span, instrument}; use opentelemetry::trace::SpanKind; -use crate::errors; +use std::path::PathBuf; +use tracing::{info_span, instrument}; use super::*; @@ -30,21 +30,25 @@ impl Command for PlanCommand { impl CommandRunnable for PlanCommand { #[instrument(name = "command.plan", fields(otel.kind = %SpanKind::Client), skip(self, matches), err)] - fn run( - &self, - matches: &clap::ArgMatches, - ) -> Result { - let config_dir: PathBuf = matches.value_of("config") - .map(|p| p.into()) - .ok_or_else(|| errors::user("No configuration directory provided.", "Provide the --config directory when running this command."))?; + fn run(&self, matches: &clap::ArgMatches) -> Result { + let config_dir: PathBuf = + matches + .value_of("config") + .map(|p| p.into()) + .ok_or_else(|| { + errors::user( + "No configuration directory provided.", + "Provide the --config directory when running this command.", + ) + })?; let mut output = crate::core::output::output(); - + let config = crate::core::config::load_all_config(&config_dir.join("config"))?; for (key, val) in config { writeln!(output, " = config {}={}", key, val)?; } - + let secrets = crate::core::config::load_all_config(&config_dir.join("secrets"))?; for (key, _val) in secrets { writeln!(output, " = secret {}=******", key)?; @@ -70,8 +74,17 @@ impl CommandRunnable for PlanCommand { let root_path = PathBuf::from("/"); let files = package.get_files()?; for file in files { - let group = package.files.get(&file.group).map(|f| f.as_path()).unwrap_or(&root_path); - writeln!(output, " + {} '{}'", if file.is_template { "template" } else { "file" }, group.join(file.relative_path).display())?; + let group = package + .files + .get(&file.group) + .map(|f| f.as_path()) + .unwrap_or(&root_path); + writeln!( + output, + " + {} '{}'", + if file.is_template { "template" } else { "file" }, + group.join(file.relative_path).display() + )?; } let tasks = package.get_tasks()?; @@ -86,16 +99,18 @@ impl CommandRunnable for PlanCommand { #[cfg(test)] mod tests { + use super::*; use crate::test::{get_test_data, test_tracing}; use mocktopus::mocking::*; - use super::*; #[test] fn run() { let _guard = test_tracing(); - + let cmd = PlanCommand {}; - let args = cmd.app().get_matches_from(vec!["plan", "--config", get_test_data().to_str().unwrap()]); + let args = + cmd.app() + .get_matches_from(vec!["plan", "--config", get_test_data().to_str().unwrap()]); let output = crate::core::output::mock(); diff --git a/src/core/config.rs b/src/core/config.rs index f0b42be..29c8346 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::Path}; use std::fs::read_to_string; use std::process; use tracing::field::display; -use tracing::{Span, instrument}; +use tracing::{instrument, Span}; use crate::errors; @@ -13,33 +13,43 @@ use mocktopus::macros::*; #[instrument(level = "debug", name = "config.load_all", err)] pub fn load_all_config(dir: &Path) -> Result, errors::Error> { if !dir.exists() { - return Ok(HashMap::new()) + return Ok(HashMap::new()); } dir.read_dir() - .map(|dirs| dirs.filter_map(|dir| match dir { - Ok(d) => match d.file_type() { - Ok(ft) if ft.is_file() => Some(d.path()), - _ => None - }, - _ => None, - })) - .map_err(|err| errors::user_with_internal( + .map(|dirs| { + dirs.filter_map(|dir| match dir { + Ok(d) => match d.file_type() { + Ok(ft) if ft.is_file() => Some(d.path()), + _ => None, + }, + _ => None, + }) + }) + .map_err(|err| { + errors::user_with_internal( "Failed to read the list of configuration files.", "Read the internal error message and take the appropriate steps to resolve the issue.", - err)) + err) + }) .and_then(|files| { let mut output = HashMap::new(); - let mut errs: Vec = files.map(|file| load_config(dunce::simplified(&file)).map(|config| { - for (key, val) in config { - output.insert(key,val); - } - })).filter(|r| r.is_err()).map(|r| r.unwrap_err()).collect(); + let mut errs: Vec = files + .map(|file| { + load_config(dunce::simplified(&file)).map(|config| { + for (key, val) in config { + output.insert(key, val); + } + }) + }) + .filter(|r| r.is_err()) + .map(|r| r.unwrap_err()) + .collect(); match errs.pop() { Some(err) => Err(err), - None => Ok(output) + None => Ok(output), } }) } @@ -86,7 +96,12 @@ fn load_env_config(file: &Path) -> Result { } #[cfg_attr(test, mockable)] -#[instrument(level = "debug", name = "config.load.script", fields(stdout, stderr), err)] +#[instrument( + level = "debug", + name = "config.load.script", + fields(stdout, stderr), + err +)] pub fn load_script_config(interpreter: &str, file: &Path) -> Result { process::Command::new(interpreter) .arg(file) diff --git a/src/core/file.rs b/src/core/file.rs index 7cdd94c..674e7fb 100644 --- a/src/core/file.rs +++ b/src/core/file.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::Path}; use walkdir::WalkDir; use gtmpl::{template, Value}; -use tracing::{instrument}; +use tracing::instrument; use crate::errors; diff --git a/src/core/mod.rs b/src/core/mod.rs index cce1d99..e20f77a 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -2,4 +2,4 @@ pub mod config; pub mod file; pub mod output; pub mod package; -pub mod script; \ No newline at end of file +pub mod script; diff --git a/src/core/package.rs b/src/core/package.rs index efd7e56..c460964 100644 --- a/src/core/package.rs +++ b/src/core/package.rs @@ -1,8 +1,11 @@ -use std::{collections::HashMap, path::{Path, PathBuf}}; use serde::*; use solvent::DepGraph; -use tracing::instrument; use std::fs; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; +use tracing::instrument; use crate::errors; @@ -29,7 +32,8 @@ impl Package { let mut pkg: Package = serde_yaml::from_slice(&content)?; pkg.path = path.to_owned(); - pkg.id = path.components() + pkg.id = path + .components() .last() .map(|c| c.as_os_str().to_string_lossy().to_string()) .unwrap(); @@ -56,25 +60,29 @@ impl Package { #[instrument(level = "debug", name = "package.load_all", err)] pub fn get_all_packages(dir: &Path) -> Result, errors::Error> { - let results = dir.read_dir() - .map(|dirs| dirs.filter_map(|dir| match dir { - Ok(d) => match d.file_type() { - Ok(ft) if ft.is_dir() => Some(d.path()), - _ => None - }, - _ => None, - })) - .map_err(|err| errors::user_with_internal( + let results = dir + .read_dir() + .map(|dirs| { + dirs.filter_map(|dir| match dir { + Ok(d) => match d.file_type() { + Ok(ft) if ft.is_dir() => Some(d.path()), + _ => None, + }, + _ => None, + }) + }) + .map_err(|err| { + errors::user_with_internal( "Failed to read the list of packages files.", "Read the internal error message and take the appropriate steps to resolve the issue.", - err))? + err) + })? .map(|p| Package::load(&p)); - let mut packages_lookup: HashMap = HashMap::new(); let mut depgraph: DepGraph<&str> = DepGraph::new(); - + for result in results { let package = result?; @@ -113,4 +121,4 @@ pub fn get_all_packages(dir: &Path) -> Result, errors::Error> { } Ok(packages) -} \ No newline at end of file +} diff --git a/src/core/script.rs b/src/core/script.rs index de846e5..1b1a1df 100644 --- a/src/core/script.rs +++ b/src/core/script.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; use std::{collections::HashMap, path::Path}; -use std::process; use itertools::Itertools; +use std::process; use tracing::field::display; use tracing::{instrument, Span}; @@ -21,26 +21,37 @@ pub struct Script { #[instrument(level = "debug", name = "script.get_all", err)] pub fn get_all_scripts(dir: &Path) -> Result, errors::Error> { if !dir.exists() { - return Ok(Vec::new()) + return Ok(Vec::new()); } - let files = dir.read_dir() - .map(|dirs| dirs.filter_map(|dir| match dir { - Ok(d) => match d.file_type() { - Ok(ft) if ft.is_file() => Some(d.path()), - _ => None - }, - _ => None, - })) - .map_err(|err| errors::user_with_internal( + let files = dir + .read_dir() + .map(|dirs| { + dirs.filter_map(|dir| match dir { + Ok(d) => match d.file_type() { + Ok(ft) if ft.is_file() => Some(d.path()), + _ => None, + }, + _ => None, + }) + }) + .map_err(|err| { + errors::user_with_internal( "Failed to read the list of tasks.", "Read the internal error message and take the appropriate steps to resolve the issue.", - err))?; + err) + })?; - Ok(files.map(|f| Script { - name: f.file_name().map(|n| n.to_string_lossy().to_string()).unwrap(), - path: dunce::simplified(&f).to_owned(), - }).sorted_by_key(|s| s.name.clone()).collect()) + Ok(files + .map(|f| Script { + name: f + .file_name() + .map(|n| n.to_string_lossy().to_string()) + .unwrap(), + path: dunce::simplified(&f).to_owned(), + }) + .sorted_by_key(|s| s.name.clone()) + .collect()) } #[cfg_attr(test, mockable)] @@ -65,7 +76,7 @@ impl Script { for (key, val) in secrets { config.insert(key.clone(), val.into()); } - + match extension { "ps1" => run_script_task("pwsh", &config, &self.path)?, "sh" => run_script_task("bash", &config, &self.path)?, @@ -79,7 +90,7 @@ impl Script { "Try using a file extension that is supported by buckle.", ))?, } - + Ok(()) } } @@ -128,13 +139,23 @@ mod tests { #[test] fn test_load() { - let path = get_test_data().join("packages").join("test1").join("scripts"); + let path = get_test_data() + .join("packages") + .join("test1") + .join("scripts"); let scripts = get_all_scripts(&path).expect("scripts should be loaded"); - + assert_eq!(scripts.len(), 1, "there should be 1 script in the package"); - + let script = &scripts[0]; - assert_eq!(script.name, "setup.ps1", "the script's name should be correct"); - assert_eq!(script.path, dunce::simplified(&path.join("setup.ps1")), "the script's path should be correct"); + assert_eq!( + script.name, "setup.ps1", + "the script's name should be correct" + ); + assert_eq!( + script.path, + dunce::simplified(&path.join("setup.ps1")), + "the script's path should be correct" + ); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 9ce3a0e..62cecf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,18 @@ extern crate clap; extern crate gtmpl; -#[macro_use] extern crate tracing; +#[macro_use] +extern crate tracing; use crate::commands::CommandRunnable; -use clap::{crate_authors, Arg, ArgMatches}; -use opentelemetry::trace::{SpanKind, StatusCode, TraceContextExt}; +use clap::{crate_authors, value_parser, Arg, ArgMatches}; +use gethostname::gethostname; +use opentelemetry::trace::{ + StatusCode, SpanKind, +}; +use opentelemetry_otlp::WithExportConfig; +use std::sync::Arc; use tracing::{field, instrument, metadata::LevelFilter, Span}; use tracing_subscriber::{prelude::*, registry}; -use std::sync::Arc; -use opentelemetry_otlp::WithExportConfig; -use gethostname::gethostname; -use tracing_opentelemetry::OpenTelemetrySpanExt; #[macro_use] mod macros; @@ -29,41 +31,23 @@ async fn main() -> Result<(), Box> { .version(version.as_str()) .author(crate_authors!("\n")) .about("Taking care of your bootstrapping needs") - - .arg(Arg::new("appinsights-key") - .long("appinsights-key") - .env("APPINSIGHTS_INSTRUMENTATIONKEY") - .help("The Application Insights API key which should be used to report telemetry.") - .takes_value(true) - .conflicts_with_all(&["honeycomb-key", "honeycomb-dataset"]) - .global(true) - .requires("appinsights-endpoint")) - .arg(Arg::new("appinsights-endpoint") - .long("appinsights-endpoint") - .env("APPINSIGHTS_ENDPOINT") - .help("The Application Insights API endpoint which should be used to report telemetry.") - .global(true) - .takes_value(true)) - - .arg(Arg::new("honeycomb-key") - .long("honeycomb-key") - .env("HONEYCOMB_APIKEY") - .help("The Honeycomb API key which should be used to report telemetry.") - .global(true) - .takes_value(true)) - .arg(Arg::new("honeycomb-dataset") - .long("honeycomb-dataset") - .env("HONEYCOMB_DATASET") - .help("The Honeycomb dataset which should be used to report telemetry.") - .takes_value(true) - .global(true) - .default_value("buckle")) - .subcommands(commands.iter().map(|x| x.app())); + .subcommands(commands.iter().map(|x| x.app())) + .arg(Arg::new("otel-endpoint") + .help("The OpenTelemetry endpoint to send traces to. This endpoint must support the OTLP protocol.") + .env("OTEL_EXPORTER_OTLP_ENDPOINT") + .long("otel-endpoint") + .takes_value(true) + .value_parser(value_parser!(String))) + .arg(Arg::new("otel-headers") + .help("The list of headers to send to the OTLP endpoint. Headers are specified as a comma-separated list of key=value pairs.") + .env("OTEL_EXPORTER_OTLP_HEADERS") + .long("otel-headers") + .takes_value(true) + .value_parser(value_parser!(String))); let matches = app.clone().get_matches(); - register_telemetry( - matches.value_of("honeycomb-team"),); + register_telemetry(&matches); std::process::exit(match host(app, commands, matches) { Ok(status) => { @@ -77,8 +61,12 @@ async fn main() -> Result<(), Box> { }); } -#[instrument(name = "app.host", fields(otel.name="buckle", otel.kind=%SpanKind::Client, otel.status=?StatusCode::Unset,exception=field::Empty, host.hostname=field::Empty, exit_code=field::Empty), skip(app, commands))] -fn host<'a>(app: clap::App<'a>, commands: Vec>, matches: ArgMatches) -> Result { +#[instrument(name = "app.host", fields(otel.name="buckle", otel.kind=%SpanKind::Client, otel.status=?StatusCode::Unset,exception=field::Empty, host.hostname=field::Empty, exit_code=field::Empty), skip(app, commands, matches))] +fn host<'a>( + app: clap::App<'a>, + commands: Vec>, + matches: ArgMatches, +) -> Result { let command_name = format!("buckle {}", matches.subcommand_name().unwrap_or("")) .trim() .to_string(); @@ -88,20 +76,23 @@ fn host<'a>(app: clap::App<'a>, commands: Vec>, matches .record("host.hostname", gethostname().to_string_lossy().trim()); match run(commands, matches) { - Ok(2) => { + Ok(status@0) => { + Span::current() + .record("otel.status", &field::debug(StatusCode::Ok)) + .record("exit_code", &status); + Ok(0) + } + Ok(status@2) => { app.clone().print_help().unwrap_or_default(); - Span::current() - .record("otel.status", &field::debug(StatusCode::Error)) - .record("exit_code", &2_u32); - - warn!("Exiting with status code {}", 2); - Ok(2) + .record("otel.status", &field::debug(StatusCode::Ok)) + .record("exit_code", &status); + Ok(0) } Ok(status) => { info!("Exiting with status code {}", status); Span::current() - .record("otel.status", &field::debug(StatusCode::Ok)) + .record("otel.status", &field::debug(StatusCode::Error)) .record("exit_code", &status); Ok(status) } @@ -119,15 +110,6 @@ fn host<'a>(app: clap::App<'a>, commands: Vec>, matches Span::current().record("exception", &error.description()); } - println!( - "Trace ID: {:032x}", - Span::current() - .context() - .span() - .span_context() - .trace_id() - ); - Err(error) } } @@ -147,24 +129,30 @@ fn run<'a>( Ok(2) } -fn register_telemetry( - honeycomb_team: Option<&str>, -) { - match honeycomb_team { - Some(honeycomb_team) if !honeycomb_team.is_empty() => { - - let mut tracing_metadata = tonic::metadata::MetadataMap::new(); - tracing_metadata.insert( - "x-honeycomb-team",honeycomb_team.parse().unwrap() - ); +fn register_telemetry(matches: &ArgMatches) { + match matches.get_one::("otel-endpoint") { + Some(otel_endpoint) if !otel_endpoint.is_empty() => { + let mut metadata = tonic::metadata::MetadataMap::new(); + + if let Some(headers) = matches.get_one::("otel-headers") { + let leaked_headers = Box::leak(headers.clone().into_boxed_str()); + leaked_headers.split_terminator(',').for_each(|x| { + if let Some((name, value)) = x.split_once('=') { + if let Some(value) = value.parse().ok() { + metadata.insert(name, value); + } + } + }); + } let tracer = opentelemetry_otlp::new_pipeline() .tracing() .with_exporter( opentelemetry_otlp::new_exporter() .tonic() - .with_endpoint("https://api.honeycomb.io:443") - .with_metadata(tracing_metadata), + .with_endpoint(otel_endpoint) + .with_metadata(metadata) + .with_env(), ) .with_trace_config(opentelemetry::sdk::trace::config().with_resource( opentelemetry::sdk::Resource::new(vec![ @@ -181,8 +169,7 @@ fn register_telemetry( .with(LevelFilter::DEBUG) .with(tracing_subscriber::filter::dynamic_filter_fn( |_metadata, ctx| { - !ctx - .lookup_current() + !ctx.lookup_current() // Exclude the rustls session "Connection" events which don't have a parent span .map(|s| s.parent().is_none() && s.name() == "Connection") .unwrap_or_default() @@ -190,17 +177,15 @@ fn register_telemetry( )) .with(tracing_opentelemetry::layer().with_tracer(tracer)) .init(); - }, + } _ => { let default_layer = tracing_subscriber::fmt::layer() .with_ansi(true) .with_writer(std::io::stderr); - - let registry = registry() - .with(LevelFilter::DEBUG) - .with(default_layer); + + let registry = registry().with(LevelFilter::DEBUG).with(default_layer); tracing::subscriber::set_global_default(registry).unwrap(); } } -} \ No newline at end of file +} diff --git a/src/test/trace.rs b/src/test/trace.rs index 761b8cc..689f227 100644 --- a/src/test/trace.rs +++ b/src/test/trace.rs @@ -5,10 +5,10 @@ pub fn test_tracing() -> DefaultGuard { let default_layer = tracing_subscriber::fmt::layer() .with_ansi(true) .with_writer(std::io::stderr); - + let registry = tracing_subscriber::registry() .with(LevelFilter::DEBUG) .with(default_layer); tracing::subscriber::set_default(registry) -} \ No newline at end of file +}