Include short sha in log messages and error urls (#1410)

As we approach our alpha release we've decided we want to plan ahead for the user bug reports we will eventually receive. One of the bigger issues we foresee is determining exactly what version of the software users are running, and particularly how easy it may or may not be for users to accidentally discard this information when reporting bugs.

To defend against this, we've decided to include the exact git sha for any given build in the compiled artifact. This information will then be re-exported as a span early in the application startup process, so that all logs and error messages should include the sha as their very first span. We've also added this sha as issue metadata for `color-eyre`'s github issue url auto generation feature, which should make sure that the sha is easily available in bug reports we receive, even in the absence of logs.

Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
Jane Lusby 2020-12-01 12:13:20 -08:00 committed by GitHub
parent de34c47cc2
commit a91d0f0bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 3 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -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<S> {
user_agent: String,
our_services: PeerServices,
relay: bool,
parent_span: Span,
}
pub struct Builder<S> {
@ -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();

View File

@ -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"

13
zebrad/build.rs Normal file
View File

@ -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!");
}

View File

@ -43,6 +43,10 @@ pub struct ZebradApp {
state: application::State<Self>,
}
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) => {

View File

@ -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<ZebradConfig> for ZebradCmd {
/// Location of the configuration file