diff --git a/Cargo.lock b/Cargo.lock index 98e047b9..073614bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3019,6 +3019,16 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "vergen" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ce50d8996df1f85af15f2cd8d33daae6e479575123ef4314a51a70a230739cb" +dependencies = [ + "bitflags", + "chrono", +] + [[package]] name = "version_check" version = "0.1.5" @@ -3345,6 +3355,7 @@ dependencies = [ "tracing-flame", "tracing-futures", "tracing-subscriber 0.2.15", + "vergen", "zebra-chain", "zebra-consensus", "zebra-network", diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index 3e232b06..ed80a610 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -15,7 +15,7 @@ use futures::{ use tokio::{net::TcpStream, sync::broadcast}; use tokio_util::codec::Framed; use tower::Service; -use tracing::{span, Level}; +use tracing::{span, Level, Span}; use tracing_futures::Instrument; use zebra_chain::block; @@ -44,6 +44,7 @@ pub struct Handshake { user_agent: String, our_services: PeerServices, relay: bool, + parent_span: Span, } pub struct Builder { @@ -136,6 +137,7 @@ where let user_agent = self.user_agent.unwrap_or_else(|| "".to_string()); let our_services = self.our_services.unwrap_or_else(PeerServices::empty); let relay = self.relay.unwrap_or(false); + Ok(Handshake { config, inbound_service, @@ -145,6 +147,7 @@ where user_agent, our_services, relay, + parent_span: Span::current(), }) } } @@ -192,7 +195,7 @@ where // set parent: None for the peer connection span, as it should exist // independently of its creation source (inbound connection, crawler, // initial peer, ...) - let connection_span = span!(parent: None, Level::INFO, "peer", addr = ?addr); + let connection_span = span!(parent: &self.parent_span, Level::INFO, "peer", addr = ?addr); // Clone these upfront, so they can be moved into the future. let nonces = self.nonces.clone(); diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index 89199035..808189b2 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -39,6 +39,9 @@ metrics-exporter-prometheus = "0.1.0-alpha.7" dirs = "3.0.1" inferno = { version = "0.10.2", default-features = false } +[build-dependencies] +vergen = "3.1.0" + [dev-dependencies] abscissa_core = { version = "0.5", features = ["testing"] } once_cell = "1.5" diff --git a/zebrad/build.rs b/zebrad/build.rs new file mode 100644 index 00000000..34c707c3 --- /dev/null +++ b/zebrad/build.rs @@ -0,0 +1,13 @@ +extern crate vergen; + +use vergen::{generate_cargo_keys, ConstantsFlags}; + +fn main() { + // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag + let mut flags = ConstantsFlags::empty(); + flags.toggle(ConstantsFlags::SHA_SHORT); + flags.toggle(ConstantsFlags::REBUILD_ON_HEAD_CHANGE); + + // Generate the 'cargo:' key output + generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); +} diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index 24956341..916ee1e4 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -43,6 +43,10 @@ pub struct ZebradApp { state: application::State, } +impl ZebradApp { + pub const GIT_COMMIT: &'static str = env!("VERGEN_SHA_SHORT"); +} + /// Initialize a new application instance. /// /// By default no configuration is loaded, and the framework state is @@ -92,6 +96,7 @@ impl Application for ZebradApp { color_eyre::config::HookBuilder::default() .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) .add_issue_metadata("version", env!("CARGO_PKG_VERSION")) + .add_issue_metadata("git commit", Self::GIT_COMMIT) .issue_filter(|kind| match kind { color_eyre::ErrorKind::NonRecoverable(_) => true, color_eyre::ErrorKind::Recoverable(error) => { diff --git a/zebrad/src/commands.rs b/zebrad/src/commands.rs index 244b9776..ab5d5ac4 100644 --- a/zebrad/src/commands.rs +++ b/zebrad/src/commands.rs @@ -8,6 +8,7 @@ use self::ZebradCmd::*; use self::{generate::GenerateCmd, start::StartCmd, version::VersionCmd}; use crate::config::ZebradConfig; +use crate::application::ZebradApp; use abscissa_core::{ config::Override, Command, Configurable, FrameworkError, Help, Options, Runnable, @@ -18,7 +19,7 @@ use std::path::PathBuf; pub const CONFIG_FILE: &str = "zebrad.toml"; /// Zebrad Subcommands -#[derive(Command, Debug, Options, Runnable)] +#[derive(Command, Debug, Options)] pub enum ZebradCmd { /// The `generate` subcommand #[options(help = "generate a skeleton configuration")] @@ -50,6 +51,19 @@ impl ZebradCmd { } } +impl Runnable for ZebradCmd { + fn run(&self) { + let span = error_span!("", zebrad = ZebradApp::GIT_COMMIT); + let _guard = span.enter(); + match self { + Generate(cmd) => cmd.run(), + ZebradCmd::Help(cmd) => cmd.run(), + Start(cmd) => cmd.run(), + Version(cmd) => cmd.run(), + } + } +} + /// This trait allows you to define how application configuration is loaded. impl Configurable for ZebradCmd { /// Location of the configuration file